0

我有一個只能在Facebook上運行的chrome擴展,我試圖將擴展收集的數據發送到我在GoDaddy網站服務器上的MySQL數據庫。我不斷收到錯誤消息「無法加載資源:服務器響應狀態爲500(內部服務器錯誤)」。我不確定是什麼問題,因爲我只是進入Web開發。 這裏是我在我的瀏覽器擴展程序內容腳本代碼:XMLHttpRequest上的內部服務器錯誤

var dummyUrl = new URL ("http://www.bbc.com/news/world-us-canada-41081629"); 
 
\t \t console.log("dummyUrl: " + dummyUrl); 
 
\t \t //Create XMLHttpRequest Object 
 
\t \t var xhttp = new XMLHttpRequest(); 
 
\t \t //Send request 
 
\t \t xhttp.open("POST", "https://pocketchange.social/data.php", true); 
 
\t \t xhttp.send(dummyUrl);

這裏是我的web服務器運行一個查詢到的數據發送到我的數據庫我的PHP文件:

<?php 
$mysqli = new mysqli("localhost", "Jarid", "Database", "myURL"); 

//Check connection 
if(mysqli === false) { 
    die("ERROR: Could not connect" . $mysqli->connect_error; 
} 

//Print host information 
echo "Connection successful. Host info: " . $mysqli->host_info; 

//Escape user inputs 
$url = $mysqli->real_escape_string($_REQUEST['url']); 
$description = $mysqli->real_escape_string($_REQUEST['description']); 
$keywords = $mysqli->real_escape_string($_REQUEST['keywords']); 
$content = $mysqli->real_escape_string($_REQUEST['content']); 
$language = $mysqli->real_escape_string($_REQUEST['language']); 

//Execute query 
$query = "INSERT INTO url_data (url, description, keywords, content, language) VALUES ('$url', '$description', '$keywords', '$content', '$language')"; 

//Checking to see if values were inserted properly 
if($mysqli->query($query) === true) { 
    echo "Data successfully inserted."; 
} 
else { 
    echo "ERROR could not execute query" . $mysqli->error; 
} 

$mysqli->close(); 
?> 

我的問題主要是,我試圖發送數據到一個完全不同的服務器?我並不是非常清楚所有這些部分如何相互通信(即,Chrome擴展如何知道如何連接到GoDaddy服務器,以及php文件如何將數據發送到數據庫等) 謝謝提前。

回答

0

關於「500(內部服務器錯誤)」,這突出顯示SO post可以給你一些想法。

500代碼通常會在服務器上顯示錯誤,而不是 任何與您的代碼。有些想法

  • 與服務器開發者交談以獲取更多信息。你無法直接獲得更多信息。
  • 驗證你的參數進入調用(值)。尋找你認爲可能導致服務器進程出現問題的任何事情。過程 不應該死,應該返回給你一個更好的代碼,但也有錯誤發生在 那裏。
  • 可能是間歇性的,就像服務器數據庫出現故障一樣。也值得嘗試在其他時間

您可以檢查後對一些可能的答案爲好。

希望這會有所幫助。