jQuery Ajax to PHP MySQL-跨域内部服务器错误(500) [英] jQuery Ajax to PHP MySQL - Cross Domain Internal Server Erro (500)

查看:252
本文介绍了jQuery Ajax to PHP MySQL-跨域内部服务器错误(500)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery ajax调用,用于使用php脚本更新数据库.

I have a jQuery ajax call to update my database using a php script.

这是我打的电话

$.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) 当我打开它时,我会发现:

The database updates and it works but in the console.log I receive this error message: POST http://domainname.com/file.php?callback=jQuery2110765103816287592_1432976576289 500 (Internal Server Error) When I open this I find this:

_.ajaxTransport.Y.cors.a.crossDomain.send @ jquery.js:26

我已经搜索并找到了有关跨域调用的内容,您必须使用jsonp等,但无法解决.谢谢!

I already searched and found about Cross Domain call stuff and you have to use jsonp etc but it didn't work out. Thx!

推荐答案

$.ajax({
        url: "update.php",
        type: 'POST',
        dataType: 'jsonp',
        data: {key1: value1, key2: value2},
        cache: false,
        crossDomain: false,
        error: function() {
            $("#failUpload").removeClass("hide");
        },
        success: function(data) {
            $("#succesUpload").removeClass("hide");
                    setTimeout(function() {
                        $("#succesUpload").addClass("hide");
                    }, 5000);
        }
   });

输入crossDomain:否,然后尝试使用此方法.

put crossDomain: false, and try with this.

这篇关于jQuery Ajax to PHP MySQL-跨域内部服务器错误(500)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆