我有一个jQuery ajax调用来更新我的数据库使用PHP脚本。jQuery Ajax到PHP MySQL - 跨域内部服务器错误(500)
这是呼叫我做:
$.ajax({
url: "update.php",
type: 'POST',
dataType: 'jsonp',
data: {key1: value1, key2: value2},
cache: false,
error: function() {
$("#failUpload").removeClass("hide");
},
success: function(data) {
$("#succesUpload").removeClass("hide");
setTimeout(function() {
$("#succesUpload").addClass("hide");
}, 5000);
}
});
PHP更新部分:
$key1 = $_POST["key1"];
$key2 = $_POST["key2"];
$con=mysqli_connect("localhost","username","password","dbname");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "UPDATE TabelName SET ". $key2 ." ='". $key1 ."' WHERE id=1";
if ($result = mysqli_query($con, $sql)) {
$resultArray = array();
$tempArray = array();
while ($row = $result->fetch_object()) {
$tempArray = $row;
array_push($resultArray, $tempArray);
}
}
mysqli_close($con);
的数据库更新和它的作品,但在执行console.log我收到此错误信息:POST http://domainname.com/file.php?callback=jQuery2110765103816287592_1432976576289 500 (Internal Server Error)
当我打开这个我找到这个:
_.ajaxTransport.Y.cors.a.crossDomain.send @ jquery.js:26
我al准备搜索并找到关于跨域调用的东西,你必须使用jsonp等,但它没有成功。谢谢!
您是否有使用JSONP进行本地请求的特定原因?尝试使用'dataType:'json''。尽管这似乎是多余的,因为您的PHP代码似乎没有在响应中返回任何数据。 –
你有没有关闭你的ajax? – Saty
我开始与json,但这给了我同样的错误...然后,我发现了跨域ajax后,其中说,使用jsonp,但同样的错误... –