Guest User

Untitled

a guest
Nov 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. Downloading jQuery
  2. How jQuery Works
  3. FAQ
  4. Tutorials
  5. Using jQuery with Other Libraries Variable Types API REFERENCE jQuery Core
  6. Selectors
  7. Attributes
  8. Traversing
  9. Manipulation
  10. CSS Events
  11. Effects
  12. Ajax
  13. Utilities
  14. jQuery UI PLUGINS Plugin Repository
  15. Authoring SUPPORT Mailing List and Chat
  16. Submit New Bug
  17. Commercial Support ABOUT JQUERY Contributors
  18. History of jQuery
  19. Sites Using jQuery
  20. Browser Compatibility
  21. Licensing
  22. Donate TOOLBOX What links here
  23. Related changes
  24. Upload file
  25. Special pages
  26. Printable version
  27. Permanent link VIEWS Article
  28. Discussion
  29. Edit
  30. History PERSONAL TOOLS Log in / create account Ajax/jQuery.post (Redirected from Post) « Back to Ajax [edit] jQuery.post( url, [data], [callback], [type] ) Overview Examples Load a remote page using an HTTP
  31. PO
  32. This is an easy way to send a simple
  33. POST request to a server without
  34. having to use the more complex $
  35. .ajax function. It allows a single callback function to be specified that
  36. will be executed when the request is
  37. complete (and only if the response has
  38. a successful response code). The returned data format can be
  39. specified by the fourth parameter. If
  40. you need to have both error and
  41. success callbacks, you may want to
  42. use $.ajax. $.post is a (simplified)
  43. wrapper function for $.ajax. $.post() returns the XMLHttpRequest
  44. that it creates. In most cases you won't
  45. need that object to manipulate directly,
  46. but it is available if you need to abort
  47. the request manually. Arguments: url String The URL of the page to load. data (Optional) Map, String Key/value pairs or the return value of
  48. the .serialize() function that will be
  49. sent to the server. callback (Optional) Function A function to be executed whenever
  50. the data is loaded successfully. function (data, textStatus) {
  51. // data could be xmlDoc, jsonObj,
  52. html, text, etc...
  53. this; // the options for this ajax
  54. request
  55. // textStatus can be one of: // "timeout"
  56. // "error"
  57. // "notmodified"
  58. // "success"
  59. // "parsererror"
  60. // NOTE: Apparently, only "success" is returned when you make
  61. // an Ajax call in this way. Other
  62. errors silently fail.
  63. // See above note about using $.ajax.
  64. } type (Optional) String Type of data to be returned to callback
  65. function: "xml", "html", "script",
  66. "json", "jsonp", or "text". $.postJSON = function(url, data,
  67. callback) { $.post(url, data, callback, "json");
  68. }; Code Gets the test.php page contents which
  69. has been returned in json format (<?
  70. php echo json_encode(array
  71. ("name"=>"John","time"=>"2pm")); ?
  72. >) $.post("test.php", { func:
  73. "getNameAndTime" },
  74. function(data){
  75. alert(data.name); // John
  76. console.log(data.time); // 2pm
  77. }, "json");
Add Comment
Please, Sign In to add comment