-1
該代碼與jQuery的工作完美:
$(document).ready(function(){
$.get("out.php", function(data) {
alert(data);
});
});
out.php
<?php echo'testing...';
但我更喜歡一個純JavaScript ...
該代碼與jQuery的工作完美:
$(document).ready(function(){
$.get("out.php", function(data) {
alert(data);
});
});
out.php
<?php echo'testing...';
但我更喜歡一個純JavaScript ...
使用XMLHttpRequest,
var xhr = new XMLHttpReuqest();
xhr.open("GET", "http://www.example.org/example.txt");
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
//handling
}
xhr.send();
https://www.w3schools.com/xml/ajax_int ro.asp – Steve
這樣的問題的第一個端口:http://youmightnotneedjquery.com。事實上,你的問題的答案在第一部分。 –
.get是.ajax的簡寫。這隱藏了很多AJAX的複雜性。我過去幾年前直接在JavaScript中使用AJAX,一旦我發現使用jQuery是多麼容易,我還沒有回頭。如果問題是通過CDN獲取jQuery(例如,在鎖定的網絡上),則可以自己託管它。爲什麼你不想使用jQuery? – manassehkatz