2015-09-29 38 views
0

我在做ajax call。每次發生故障時,都會發生500 Internal server error。但是客戶端代碼沒有錯誤。ajax調用發生內部服務器錯誤

JavaScript代碼:

$.ajax({ 
    url:"test.php", 
    type:"POST", 
    dataType:"html", 
    data:{ 
     userInput:userInput /* userInput is some text value */ 
    } 
}); 

PHP代碼:

<?php 
    $con=mysqli_connect("localhost","root","password","test"); 
    $user_data=$_POST['userInput']; 
    echo $user_data; 
?> 
每當我看到控制檯這些錯誤代碼的時間

POST XHR http://localhost/test.php[HTTP/1.0 500 Internal Server Error 1ms]

問我,如果你需要更多信息

NB:我在這個社區發現了很多問題。 這些都解決了我的問題

+1

你從哪裏得到這個想法,有500錯誤?它很清楚地表示_404 Not Found_,它表明url(localhost/test.php)不正確。還可以嘗試向'$ .ajax'調用添加成功和錯誤回調,以便您可以在那裏記錄更多信息 –

+0

您確定'test.php'實際上位於服務器的根目錄嗎? – hjpotter92

+0

你確定test.php和你使用ajax的文件在同一個目錄下嗎? – SHAZ

回答

0

您可以趕上你的錯誤執行的回調..例如:

$.ajax({ 
    url:"test.php", 
    type:"POST", 
    dataType:"html", 
    data:{ 
     userInput:userInput /* userInput is some text value */ 
    } 
}).success(function() { 
    window.alert('Ajax completed successfully'); 
}).error(function() { 
    window.alert('An error has occurred'); 
}); 
2

我覺得內部服務器錯誤是由於與mysqli擴展的mysqli_connect函數調用未啓用。嘗試phpifo()驗證啓用了mysqli擴展

+0

客戶端API庫版本\t 44年5月5日 活動持久連接無效持久連接活動鏈接客戶端API頭版本\t 44年5月5日 MYSQLI_SOCKET \t /var/run/mysqld/mysqld.sock 指令\t本地價值\t主值 mysqli.allow_local_infile \t在\t在 mysqli.allow_persistent \t在\t在 mysqli.default_host \t沒有值\t沒有值 mysqli.default_pw \t沒有價值\t沒有值 mysqli.default_socket \t \t /var/run/mysqld/mysqld.sock /var/run/mysqld/mysqld.sock mysqli.default_user \t沒有價值\t沒有價值 mysqli.max_links \t無限\t無限 mysqli.max_persistent \t無限\t無限 mysqli.reconnect \t關\t關 – partho

+0

檢查Apache日誌。可能會發現哪裏出了問題。 –

+0

你懷疑是對的。評論'mysqli_connect'我看不出錯誤。 'mysqli'未啓用。我正在嘗試啓用它。請幫幫我?使用'ubuntu 14.04 LTS' – partho

相關問題