//Function: Add the data returned by the server directly to the DOM object that meets the requirements //Equivalent to obj .innerHTML = Data returned by the server
Usage: $obj.load(url,[request parameters]);
url: Request address Request parameters: The first form: request string, such as: 'username=zs&age=22' The second form: object, such as {'username':'zs','age':22}
//Note: //a, if the load method has no parameters, it will use the get method to send the request. If there are parameters, the post method will be used to send the request. //b, if there are Chinese parameter values, the load method has already done the encoding for us.
url: request address data: request parameters, the form is the same as above. callback: callback function, which can be used to process the data returned by the server. Callback format:
function(data, statusText),
Among them, data can get the data returned by the server, statusText is a simple string describing the processing by the server state.
type: The data type returned by the server. The type can be: html: Returns html content. text: Returns text. json: returns a json string xml: returns a DOM-compatible xml object script: returns javascriptz
function quoto(){ $.post('quoto.do',function(data) { //If the data returned by the server is a json string, //will be automatically converted into a js object or an array of json objects. $('#tb1').empty(); for(i=0;i$('#tb1').append( '
' data[i].code '
' data[i].name '
' data[i].price '
< /tr>'); } },'json');t }
1.3.$.ajax(options):
/ /options is a js object in the shape of {key1:value1,key2:value2...}, used to specify options for sending requests.
option parameters are as follows:
url(string) : //Request address type(string) : //GET/POST data(object/string) : // Data sent to the server dataType(string): //The data type expected to be returned by the server success(function): //The callback function called after the request is successful, has two parameters: function(data , textStatus), where data is the data returned by the server, textStatus is a string describing the status. error(function): //Function called when the request fails, with three parameters function(xhr, textStatus, errorThrown), where xhr is the underlying ajax object (XMLHttpRequest), textStatus , one of the two parameters errorThrown can obtain the underlying exception description. async:true (default)/false: //When the value is false, send a synchronous request.
$.ajax({ 'url':'carInfo. do', 'type':'post', 'data':'carName=' $('#s1').val(), 'dataType':'xml', 'success':function(data){ //data is the data returned by the server //If an xml document is returned, we need to use //$function to wrap it $(data) into a jQuery //object for easy search //clear before appending $('#tb1').empty(); $('#tb1').append( '
//Convert the form or form control contained in the jquery object into a query string.
2.2.serializeArray():
//Convert to an array, each array element is an object in the shape of {name:fieldName,value:fieldVal}. //The role of serialized elements is mainly used in ajax requests to assign values to data.
Note: can only be used for forms or form controls Send the name of the form and the corresponding value directly, in the form: name=value
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn