Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts

    Question jQuery ready states

    Hi,

    Just wondering whats the function used in jQuery for ajax XMLHttpRequest

    Like the following


    0 The request is not initialized
    1 The request has been set up
    2 The request has been sent
    3 The request is in process
    4 The request is complete


    More info here: http://www.w3schools.com/ajax/ajax_xmlhttprequest.asp



    Thanx

  • #2
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts
    You shouldn't ever need to probe those individual states when using jQuery to make an Ajax connection. The function jQuery.ajax() supports the "error", "success", and "complete" parameters that let you fire your own custom code for any of the relevant Ajax outcomes. Something like:

    Code:
    		$.ajax({
    			url: "myscript.php"
    			async: true,
    			error:function(ajaxrequest){
    				alert('Error fetching content.<br />Server Response: '+ajaxrequest.responseText)
    			},
    			success:function(content){
    				alert(content)
    			}
    		})
    Native XMLHttpRequest states like 1 or 2 don't ever fire at all in some browsers, so they are not reliable anyway.
    - George
    - JavaScript Kit- JavaScript tutorials and 400+ scripts!
    - JavaScript Reference- JavaScript reference you can relate to.

  • Users who have thanked WA for this post:

    phantom007 (07-03-2008)

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts
    Hi,

    Can this be done with $.get method?

    If yes, can ya show an example plz?


    Thanx

  • #4
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts
    Well, $.get() is basically just a shorthand, limited version of $.ajax(). I don't believe it gives you access to some of the states you mentioned:

    Ajax/jQuery.get:

    Load a remote page using an HTTP GET request.
    This is an easy way to send a simple GET request to a server without having to use the more complex $.ajax function. It allows a single callback function to be specified that will be executed when the request is complete (and only if the response has a successful response code). If you need to have both error and success callbacks, you may want to use $.ajax.
    Why not just use the lower level, $.ajax() method?
    - George
    - JavaScript Kit- JavaScript tutorials and 400+ scripts!
    - JavaScript Reference- JavaScript reference you can relate to.

  • Users who have thanked WA for this post:

    phantom007 (07-03-2008)

  • #5
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts
    Question:

    Can I have 2 Submit buttons in a form one for adding and the other for deleting?

    Well, I wanna do the addition and deletion in jQuery.

    How do I implement the condition statement in jQuery that if submit button is add then do the add function and if the submit button is delete then do the delete function?


    Thanx

  • #6
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Sounds like you need two different functions that do either of those steps.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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