This time I will show you how to use the ajax.load() method in jQuery. What are the precautions when using the ajax.load() method in jQuery. The following is a practical case. Let’s take a look. one time.
jQuery load() method
jQuery load() method is a simple but powerful AJAX method.
The load() method loads data from the server and puts the returned data into the selected element.
Syntax:
$(selector).load(URL,data,callback);
The load() function is used to load data from the server and replace the content of the current matching element with the returned html content .
The load() function uses the GET method by default. If data in object form is provided, it will automatically switch to the POST method.
Because the Get request method is used by default, we can also add data to the url for submission.
For example$("#box").load("loadTest.html?name=zhang&age=25")
load() method can be parameterized Count three parameters:
url (required, the url address of the requested html file, the parameter type is String)
data (optional, the key/value data sent, the parameter type Is Object)
callback (optional, successful or failed callback function, parameter type is Function)
## The #load() method is a local method because it requires a jQuery object containing the element as a prefix. For example, $("#box").load() and $.get() and $.post() are global methods and do not need to specify an element. For purposes, .load() is suitable for asynchronous acquisition ofstatic files,
and for those that need to pass parameters to the server page, $.get() and $.post() More appropriate. The optional callback parameter specifies the callback function to be allowed when the load() method completes. The callback function can set different parameters:
$("button").click(function(){ $("#p1").load("demo_test.txt",function(responseTxt,statusTxt,xhr){ if(statusTxt=="success") alert("外部内容加载成功!"); if(statusTxt=="error") alert("Error: "+xhr.status+": "+xhr.statusText); }); });
How to use json as a parameter in js
ajax php control function call Detailed explanation of steps
The above is the detailed content of How to use the ajax.load() method in jQuery. For more information, please follow other related articles on the PHP Chinese website!