在我的虛擬Ubuntu的機器上工作,我有AJAX這部分代碼在我的Windows8AJAX並不遠程服務器
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js "></script>
<script>
$(document).ready(function(){
$('#next_Button').click(function(){
var text = document.getElementById("textbox");
var query = text.value;
$('#response').html("<b>Loading response...</b>");
$.ajax({
type: 'POST',
url: 'http://192.168.92.131/search2/info.php',
data: { query : query }
})
.done(function(data){
$('#response').html(data);
alert("sent query");
})
.fail(function() {
alert("Posting failed.");
});
return false;
});
});
</script>
和PHP代碼
echo $_POST['query'];
IP地址是正確的,它總是固定。但阿賈克斯總是說'張貼失敗'。當我把HTML代碼放在服務器上,並設置網址:'search2/info.php' 它的工作原理。但是當它使用http:// ipaddress/search2/phpname的遠程服務器時,它不起作用。順便說一下,我的PHP代碼是在Apache上託管的var/www/html/search2中。 從ajax這個問題?即使當我點擊這個完整的網址,它顯示服務器頁面!但阿賈克斯不能使用這個直接的網址.php!
其他域名正在阻止ajax。 thanx的提示! – patric