我試圖做一個PHP連接,但我不斷收到此錯誤。我希望有人能幫忙。Ajax,未能從服務器加載PHP
我的代碼提供了以下錯誤:
{
"readyState": 0,
"status": 0,
"statusText": "NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost/php/busca.php'."
}
我的代碼是:
SendSQL.onclick = function() {
var dataString='a=hello&b=world';
$.ajax({
type: "POST",
url:"http://localhost/php/busca.php",
data: dataString,
async: false,
dataType:'html',
success: function(data){
alert(data);
},
error: function(data){
alert(JSON.stringify(data)); //Better diagnostics
}
});
};
和文件busca.php是:
<?php
$a = $_POST['a'];
$b = $_POST['b'];
echo "$a, $b";
?>
是什麼SendSQL? – epascarello
可能重複的[NetworkError:無法執行'XMLHttpRequest'發送'](https://stackoverflow.com/questions/32878613/networkerror-failed-to-execute-send-on-xmlhttprequest) – aynber
在javascritp它是var SendSQL = document.getElementById('SendSQL');但是在html上是一個按鈕: –