ກົນລະບຽບ jQuery AJAX load()
- ການໄປຫາບ່ອນຫນັງ ຂໍ້ສະເພາະຂອງ jQuery AJAX
- ການໄປຫາບ່ອນຕໍ່ໄປ jQuery Get/Post
ກົນລະບຽບ jQuery load()
ກົນລະບຽບ jQuery load() ແມ່ນກົນລະບຽບ AJAX ທີ່ງາມກະດ້ານທີ່ສຸດແລະມີຄວາມອິດທິພົນ.
ກົນລະບຽບ load() ກຳລັງການອ່າງຂໍ້ມູນຈາກບໍລິສັດທະນາຄານ ແລະ ພື້ນຖານຂໍ້ມູນທີ່ກັບຄືນມາສະເພາະພິມໃສ່ສະມາຊິກທີ່ເລືອກ.
ວິນິຍົມວິທະຍາສາດ:
$("}}selector).load(URL,data,callback);
Required URL The parameter specifies the URL you want to load.
Optional data The parameter specifies the set of key/value pairs sent with the request.
Optional callback The parameter is the name of the function to be executed after the load() method is completed.
This is the content of the example file ("demo_test.txt"):
<h2>jQuery and AJAX is FUN!!!</h2> <p id="p1">This is some text in a paragraph.</p>
The following example will load the content of the file "demo_test.txt" into the specified <div> element:
Example
$("#div1").load("demo_test.txt");
You can also add jQuery selector to the URL parameters.
The following example loads the content of the element with id="p1" in the file "demo_test.txt" into the specified <div> element:
Example
$("#div1").load("demo_test.txt #p1");
The optional callback parameter specifies the callback function to be allowed after the load() method is completed. The callback function can set different parameters:
- responseTxt - Contains the result content when the call is successful
- statusTXT - Contains the call status
- xhr - Contains XMLHttpRequest object
The following example will display a dialog box after the load() method is completed. If the load() method is successful, it will display "External content loaded successfully!" and if it fails, it will display an error message:
Example
$("button").click(function(){ $("#div1").load("demo_test.txt",function(responseTxt,statusTxt,xhr){ if(statusTxt=="success") alert("External content loaded successfully!"); if(statusTxt=="error") alert("Error: "+xhr.status+": "+xhr.statusText); }); });
ຄູ່ມືຂອງ jQuery AJAX
ສຳລັບການກວດສອບວິທີ AJAX ທີ່ສົມບູນກາງຫນັງວິທີ,ກະລຸນາເຂົ້າຊອກຄືວັນດັ່ງກ່າວ ຄູ່ມືຂອງ jQuery AJAX。
- ການໄປຫາບ່ອນຫນັງ ຂໍ້ສະເພາະຂອງ jQuery AJAX
- ການໄປຫາບ່ອນຕໍ່ໄປ jQuery Get/Post