Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Downloading jQuery
- How jQuery Works
- FAQ
- Tutorials
- Using jQuery with Other Libraries Variable Types API REFERENCE jQuery Core
- Selectors
- Attributes
- Traversing
- Manipulation
- CSS Events
- Effects
- Ajax
- Utilities
- jQuery UI PLUGINS Plugin Repository
- Authoring SUPPORT Mailing List and Chat
- Submit New Bug
- Commercial Support ABOUT JQUERY Contributors
- History of jQuery
- Sites Using jQuery
- Browser Compatibility
- Licensing
- Donate TOOLBOX What links here
- Related changes
- Upload file
- Special pages
- Printable version
- Permanent link VIEWS Article
- Discussion
- Edit
- 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
- PO
- This is an easy way to send a simple
- POST 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). The returned data format can be
- specified by the fourth parameter. If
- you need to have both error and
- success callbacks, you may want to
- use $.ajax. $.post is a (simplified)
- wrapper function for $.ajax. $.post() returns the XMLHttpRequest
- that it creates. In most cases you won't
- need that object to manipulate directly,
- but it is available if you need to abort
- 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
- the .serialize() function that will be
- sent to the server. callback (Optional) Function A function to be executed whenever
- the data is loaded successfully. function (data, textStatus) {
- // data could be xmlDoc, jsonObj,
- html, text, etc...
- this; // the options for this ajax
- request
- // textStatus can be one of: // "timeout"
- // "error"
- // "notmodified"
- // "success"
- // "parsererror"
- // NOTE: Apparently, only "success" is returned when you make
- // an Ajax call in this way. Other
- errors silently fail.
- // See above note about using $.ajax.
- } type (Optional) String Type of data to be returned to callback
- function: "xml", "html", "script",
- "json", "jsonp", or "text". $.postJSON = function(url, data,
- callback) { $.post(url, data, callback, "json");
- }; Code Gets the test.php page contents which
- has been returned in json format (<?
- php echo json_encode(array
- ("name"=>"John","time"=>"2pm")); ?
- >) $.post("test.php", { func:
- "getNameAndTime" },
- function(data){
- alert(data.name); // John
- console.log(data.time); // 2pm
- }, "json");
Add Comment
Please, Sign In to add comment