w3schoon Posted February 26, 2013 Share Posted February 26, 2013 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. Link to comment Share on other sites More sharing options...
thescientist Posted February 26, 2013 Share Posted February 26, 2013 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. Link to comment Share on other sites More sharing options...
w3schoon Posted February 27, 2013 Author Share Posted February 27, 2013 Thank you very much, now I understand. How about ajax=2 or 3 or 4 or n... ? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 27, 2013 Share Posted February 27, 2013 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. Link to comment Share on other sites More sharing options...
thescientist Posted February 27, 2013 Share Posted February 27, 2013 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. Link to comment Share on other sites More sharing options...
w3schoon Posted March 2, 2013 Author Share Posted March 2, 2013 What do you mean JSG? Till now I don't understand what the usage of ajax=1 when it pass to the path i.e. url Link to comment Share on other sites More sharing options...
jeffman Posted March 2, 2013 Share Posted March 2, 2013 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. 1 Link to comment Share on other sites More sharing options...
w3schoon Posted March 3, 2013 Author Share Posted March 3, 2013 Thanks a lot guys. Good explanations, I got what you mean. Now I know the usage data: in Ajax... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now