Copy Code code as follows:
function PostData () {//Submit data functions
$.ajax ({//Call jquery Ajax method
Type: "POST",//Setting the format of the Ajax method submission data
URL: "ok.php",//Submit data to ok.php
Data: "Writer=" +$ ("#writer"). Val (),//The value in the input box writer as the submission
Success:function (msg) {//After a successful callback, the MSG variable is the content of the ok.php output.
Alert ("Data submitted successfully"); If necessary, you can display the value of the MSG variable in a DIV element
}
});
}
jquery Manual Description:
Data sent to the server. is automatically converted to the request string format. The GET request is appended to the URL. View the ProcessData option description to prevent this automatic conversion. Must be in the Key/value format. If you are an array, JQuery will automatically correspond to the same name for different values. such as {foo:["bar1", "Bar2"]} is converted to ' &foo=bar1&foo=bar2 '.
Example:
Copy Code code as follows:
$.ajax ({
Type: "POST",
URL: "some.php",
Data: "Name=john&location=boston",
Success:function (msg) {
Alert ("Data Saved:" + msg);
}
});
The parameters behind this data can be used in two types of tables: One is the normal URL argument, and one is written in the JSON array,
The above example data section can also be written like this: data: {name: "John", Location: "Boston"}. What is the difference between these two usages?
The nuances of usage are found today in development. The first one we use the URL to pass the parameter, if you add the symbol "&", the parameters may not receive or incomplete, such as "Data:" Name=john&location=boston ",",
If the value of name is "John&smith" This may be a problem, we can use JS inside the encodeURIComponent () method to escape,
But if you use data: {name: "John", Location: "Boston"} is written in this way, there is no need to escape, if escaped, will receive the escaped string