XMLHttpRequest上的内部服务器错误

问题描述:

我有一个仅在Facebook上运行的chrome扩展程序,我正尝试将扩展程序收集的数据发送到GoDaddy网站服务器上的MySQL数据库.我一直收到错误消息无法加载资源:服务器响应状态为500(内部服务器错误)".由于我刚开始进行Web开发,因此不确定是什么问题.这是我在chrome扩展程序中的内容脚本代码:

I have a chrome extension that only runs on Facebook and I am trying to send data that the extension gathers to a MySQL database that I have on my GoDaddy website server. I keep getting the error message "Failed to load resource: the server responded with a status of 500 (Internal Server Error)". I wasn't sure what the issue is since I'm just getting into web development. Here is my code for the content script on my chrome extension:

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

这是我的网络服务器上的PHP文件,该文件正在运行查询以将数据发送到我的数据库:

And here is my PHP file on my webserver that is running a query to send the data to my database:

<?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文件将数据发送到数据库的确切方式,等等).预先感谢.

Is my issue mainly that I'm trying to send data to a completely different server? I'm not super clear on how all of these pieces communicate with each other (ie how does the chrome extension know how to connect to the GoDaddy server, and how exactly is the php file sending data to the database, etc.) Thanks in advance.

关于"500(内部服务器错误)",此突出显示了

Regarding the "500 (Internal Server Error)", this highlighted SO post could give you some idea.

500码通常会指示服务器上的错误,而不是任何与您的代码有关的内容.一些想法

The 500 code would normally indicate an error on the server, not anything with your code. Some thoughts

  • 与服务器开发人员联系以获取更多信息.您无法直接获得更多信息.
  • 验证您的参数是否包含在调用中(值).查找您认为可能会导致服务器进程出现问题的任何内容.过程应该不会死,应该返回更好的代码,但是会发生错误还有.
  • 可能是间歇性的,例如服务器数据库出现故障.也许值得在其他时间尝试

您也可以在帖子中查看一些可能的答案.

You can check the post for some possible answer as well.

希望这会有所帮助.