Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-02-2008, 01:06 PM   PM User | #1
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
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
cancer10 is offline   Reply With Quote
Old 07-02-2008, 10:53 PM   PM User | #2
WA
Administrator


 
Join Date: Mar 2002
Posts: 2,596
Thanks: 2
Thanked 19 Times in 18 Posts
WA will become famous soon enough
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.
WA is offline   Reply With Quote
Users who have thanked WA for this post:
cancer10 (07-03-2008)
Old 07-03-2008, 04:59 AM   PM User | #3
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
Hi,

Can this be done with $.get method?

If yes, can ya show an example plz?


Thanx
cancer10 is offline   Reply With Quote
Old 07-03-2008, 07:54 AM   PM User | #4
WA
Administrator


 
Join Date: Mar 2002
Posts: 2,596
Thanks: 2
Thanked 19 Times in 18 Posts
WA will become famous soon enough
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:

Quote:
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.
WA is offline   Reply With Quote
Users who have thanked WA for this post:
cancer10 (07-03-2008)
Old 07-03-2008, 08:51 AM   PM User | #5
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
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
cancer10 is offline   Reply With Quote
Old 07-07-2008, 01:36 PM   PM User | #6
A1ien51
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
A1ien51 will become famous soon enough
Sounds like you need two different functions that do either of those steps.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:06 AM.


Advertisement
Log in to turn off these ads.