SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: onclick issue

  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    onclick issue

    Hai folks,

    in below code the refresh(); , an ajax function does not invoke

    Code:
    onclick="add_emp();refresh();"
    but this works

    Code:
    onclick="add_emp();refresh();refresh();refresh();refresh();"
    Now it works . Strange trick is it

    So whats the problem really?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by afridy View Post
    So whats the problem really?
    Is there a way for us to experience (and thus troubleshoot) the same problem?

    Without knowing more about your particular situation, the standard technique is to pass a callback to the ajax function, so that the data on a successful request can be passed to the callback.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hai paul,

    its not possible to generate the problem simply. coz it a whole lot of coding.
    in summary i can tell like this

    * form.php have a div with the id of 'res'. also have a text box and a button. now user enters the employee number and click the button.

    so add_emp() will be executed in the following order: button click > ajax call > php ad record

    * now reloading all the employee data in to the res div using refresh() : ajax call > php load data from table.

    problem is , this loading does not occur if i use only 1 refresh().

  4. #4
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    oops, i fogot,

    if i put an alert(); in the refresh ajax function as follows even works!!

    Code:
    function refresh(){
    	
           alert('hai');
    
    	var xmlhttp;
    	
    	if (window.XMLHttpRequest){
    	  // code for IE7+, Firefox, Chrome, Opera, Safari
    	  xmlhttp=new XMLHttpRequest();
    	}else{
    	  // code for IE6, IE5
    	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by afridy View Post
    problem is , this loading does not occur if i use only 1 refresh().
    The load part shouldn't occur after the ajax call, because data is still being transferred.
    Instead, the load part needs to occur only when the the success event occurs for the ajax command.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    The load part shouldn't occur after the ajax call, because data is still being transferred.
    Instead, the load part needs to occur only when the the success event occurs for the ajax command.
    Thanks paul for the valuable info.

    so i think i could use the readyState==4 && xmlhttp.status==200 in the first ajax file to handle this situation ...

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    There's a book called Bulletproof Ajax that gives all the details on how to do that well.
    They provide code and examples from the book on their website too, from which much learning can be done.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    There's a book called Bulletproof Ajax that gives all the details on how to do that well.
    They provide code and examples from the book on their website too, from which much learning can be done.
    sure,ill consider about this book . thanks a lot.


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
  •