duankan8739 2015-05-30 11:07
浏览 95

jQuery Ajax到PHP MySQL - 跨域内部服务器错误(500)

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

This is the call I make:

$.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 Update part:

$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);

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

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

  • 写回答

4条回答 默认 最新

  • douxiu6835 2015-05-30 11:24
    关注

    Use following function for error. It will show the exact issue. I think it will help.

    error : function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.responseText+errorThrown+textStatus);
                    $("#failUpload").removeClass("hide");
            }
    

    All the best.

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)