Jump to content
w3schoon

JQuery $.ajax() Basics

Recommended Posts

Nice be with you everyone! I'm planing to use JQuery $.ajax() method to delete 1 row of my database. While searching I found this on the web...

 			$.ajax({				type: 'get',				url: '/examples/delete.php',				data: 'ajax=1&delete=' + $(this).attr('id'),				success: function() {					parent.fadeOut(300,function() {						parent.remove();				});			}		});

I have questions: 1. What is the difference of post & get in the type: ?2. What is the usage of 'ajax=1&delete=' in the data: ?3. If there is success: how about if not success, I mean error handler? Thank you.

Share this post


Link to post
Share on other sites

1 + 3) you can get from the documentationhttp://api.jquery.com/jQuery.ajax/ but basically it specifies the type of request you are making to the server, which will in turn determine how you implement it. (i.e. GET vs. POST). It has more meaning in the context of REST'ful HTTP requests, but that might be beyond the scope of this example. 2) it is a query string. ajax=1 could indicate that the request is being initiated from the client side via the web application itself (not a direct access of delete.php, although this could be spoofed), and delete could confirm the kind of request that is being made. This all specific to the internals of delete.php itself however.

Share this post


Link to post
Share on other sites

What about it? You can set any variable to any value you want, and you can write your code to look for any value you want.

Share this post


Link to post
Share on other sites
Thank you very much, now I understand. How about ajax=2 or 3 or 4 or n... ?
2) it is a query string. ajax=1 could indicate that the request is being initiated from the client side via the web application itself (not a direct access of delete.php, although this could be spoofed), and delete could confirm the kind of request that is being made. This all specific to the internals of delete.php itself however.
the point I was trying to make is that only the developer knows. As JSG said, you could make it anything you want.

Share this post


Link to post
Share on other sites

JSG is justsomeguy. No one likes typing all that. Some people call me DD. Same reason. There is no special meaning to ajax=1 or any other query string. It is not part of the HTML rules or the jQuery API. The word "ajax" in a query string is an example of a variable name chosen by the developer. Instead of "ajax=1" the developer could have written "w3schoon=1". For the same reason, there is no special meaning to "1" or "2" or "3" . . . It's just an example. YOU are the developer. You choose the data you want to send to your server in a query string. You also program a script on your server to understand what that data means.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...