Results 1 to 3 of 3

Thread: Execute javascript after ajax called

  1. #1
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Execute javascript after ajax called

    Execute javascript after ajax called

    this is my big problem and i gone to hate AJAX

    I made this code with jquery and without it and it's same thing
    when i call the page by ajax it's dosent execute

    PHP Code:

    <script type="text/javascript" src="dfile/js/jquery.js"></script>
    <script type="text/javascript">


    function checkme(){

    if ($('#name').val()== '' || $('#name').val().length < 3 || $('#mail').val().indexOf('@')== -1 || $('#mail').val().indexOf('.')== -1 || $('#mail').val().length < 7 || $('#domain').val()== '' || $('#domain').val().length < 3 || $('#domain').val().indexOf('.')== -1)
    {
    $(adoption_it).attr("disabled", true);
    }else{$(adoption_it).removeAttr("disabled");}
    };


    </script>
    <body>


    <input type=text id=name size=21 class="earea" onkeydown="checkme()"><br />
    <input type=text id=mail size=21 class="earea" onkeydown="checkme()"><br />
    <input type=text id=domain size=21 class="earea" onkeydown="checkme()"><br />
    <input type=button id="adoption_it" value="do" onclick="" disabled><br />
    <input type=button value="R" onclick="checkme()"><br />
    </body> 
    I thing the have function in jquery it name .live() to fix this problem
    but i dont know how to exploitation it here

    http://docs.jquery.com/Events/live
    or
    http://docs.jquery.com/Frequently_As...JAX_request.3F

    please i need to fix this with with or without jquery

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    jQuery live only works with jQuery 1.3+.

    Anyways, there are two basic approaches. Either you listen to the page and determine if any event that occurs qualifies for your script, or you add your event to the new content after it is imported.

    In a typical non-jQuery AJAX import you eventually see something like so (from Ajax post# 23):

    Code:
    loadXmlHttp.prototype.stateChanged = function(){
     if (this.xmlHttp.readyState == 4 && (this.xmlHttp.status == 200 || !loadXmlHttp.re))
      this.el.innerHTML = this.xmlHttp.responseText;
    }
    Once the code is imported:

    Code:
    this.el.innerHTML = this.xmlHttp.responseText;
    You can then initialize it:

    Code:
    loadXmlHttp.prototype.stateChanged = function(){
     if (this.xmlHttp.readyState == 4 && (this.xmlHttp.status == 200 || !loadXmlHttp.re))
      this.el.innerHTML = this.xmlHttp.responseText;
      do something else here to init the just imported code
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi first thank you
    second it's doesn't work

    look to what i make

    PHP Code:

    <script type="text/javascript" src="dfile/js/jquery.js"></script>

    <script type="text/javascript">


    function aClick() {

    if ($('#name').val()== '' || $('#name').val().length < 3 || $('#mail').val().indexOf('@')== -1 || $('#mail').val().indexOf('.')== -1 || $('#mail').val().length < 7 || $('#domain').val()== '' || $('#domain').val().length < 3 || $('#domain').val().indexOf('.')== -1)
    {
    $(adoption_it).attr("disabled", true);
    }else{
    $(adoption_it).removeAttr("disabled");}

    }


    function loadXmlHttp(url, id) {
     var f = this;
     if (loadXmlHttp.xmlHttp){
      f.xmlHttp = loadXmlHttp.xmlHttp();
      f.el = document.getElementById(id);
      f.xmlHttp.open("GET", url, true);
      f.xmlHttp.onreadystatechange = function(){f.stateChanged();};
      f.xmlHttp.send(null);
     }
     else alert('Your browser does not support AJAX!'); // substitute your desired request object unsupported code here
    }

    loadXmlHttp.xmlHttp = null; loadXmlHttp.re = /^http/.test(window.location.href);
    /*@cc_on @*/ // used here and below, limits try/catch to those IE browsers that both benefit from and support it
    /*@if(@_jscript_version >= 5) // prevents errors in old browsers that barf on try/catch & problems in IE if Active X disabled
    try {loadXmlHttp.ie = window.ActiveXObject}catch(e){};
    @end @*/
    if (window.XMLHttpRequest && (!loadXmlHttp.ie || loadXmlHttp.re))
     loadXmlHttp.xmlHttp = function(){return new XMLHttpRequest();}; // Firefox, Opera 8.0+, Safari, others, IE 7+ when live - this is the standard method
    else if (/(object)|(function)/.test(typeof createRequest))
     loadXmlHttp.xmlHttp = createRequest; // ICEBrowser, perhaps others
    else {
     loadXmlHttp.xmlHttp = null;
    // Internet Explorer 5 to 6, includes IE 7+ when local //
    /*@if(@_jscript_version >= 5)
    try{loadXmlHttp.xmlHttp = function(){return new ActiveXObject("Msxml2.XMLHTTP");};}
     catch(e){try{loadXmlHttp.xmlHttp = function(){return new ActiveXObject("Microsoft.XMLHTTP");};}catch(e){}}
    @end @*/
    }

    loadXmlHttp.prototype.stateChanged = function(){
     if (this.xmlHttp.readyState == 4 && (this.xmlHttp.status == 200 || !loadXmlHttp.re))
      this.el.innerHTML = this.xmlHttp.responseText;

    // in this code i try to add whole the code and it's same thing
    // and in other way i just put the function like aClick() and also doesn't work

    if ($('#name').val()== '' || $('#name').val().length < 3 || $('#mail').val().indexOf('@')== -1 || $('#mail').val().indexOf('.')== -1 || $('#mail').val().length < 7 || $('#domain').val()== '' || $('#domain').val().length < 3 || $('#domain').val().indexOf('.')== -1)
    {
    $(adoption_it).attr("disabled", true);
    }else{
    $(adoption_it).removeAttr("disabled");}

    }

    </script>

    </head>
    <body>
    <br />
      
    <div id="et3rnal"></div><br />

    <input type="button" onclick="new loadXmlHttp('test.php', 'et3rnal')" value="do"><br />

    </body> 
    in test.php file just put

    PHP Code:

    <input type=text id=name size=21 class="earea" onkeydown="//checkme()"><br />
    <
    input type=text id=mail size=21 class="earea" onkeydown="//checkme()"><br />
    <
    input type=text id=domain size=21 class="earea" onkeydown="//checkme()"><br />
    <
    input type=button id="adoption_it" value="do"><br />
    <
    input type=button value="O" onclick="aClick()"><br /> 
    can you pleas make an example

    in this way it's same nothing coz it's also work in one time
    just in first called

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •