Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jqueryajax出错了_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript jqueryajax出错了

Javascript jqueryajax出错了,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,将数据类型设置为Json后,我的ajax函数出错。 这就是代码: Ajax脚本: $('#da').on("change",function() { $.ajax({ url: "callAjaxIndex.php", type: "POST", dataType: "json", data: { meth

将数据类型设置为Json后,我的ajax函数出错。 这就是代码:

Ajax脚本:

$('#da').on("change",function() {
            $.ajax({
                url: "callAjaxIndex.php",
                type: "POST",
                dataType: "json",
                data: {
                    method: 1,
                    id: $('#da').val(),
                },
                success: function() {
                    alert('test');
                },
                error: function() {
                    alert('error');
                }
            });
        });
callAjaxIndex.php

<?PHP
require('includes/core.php');
if ( isset($_POST['method']) ) {
    $sql = "SELECT tratte.nome as 'nome_arrivo', tratte.id as 'id_arrivo' FROM tariffe, tratte WHERE id_arrivo = tratte.id AND id_partenza = '".$_POST['id']."'";
    $query = $conn->query($sql);
    while ( $tariffe = $query->fetch_array() ) {
        $result[] = array(
            'id' => $tariffe['id_arrivo'],
            'nome' => $tariffe['nome_arrivo']
        );
    }
    echo json_encode($result);
}
?>
您可以试试这个

$(document).on('change','da',function(){
$.post(“callAjaxIndex.php”,{'method':1,'id':$(this.val()},函数(数据){
var d=$.parseJSON(数据);//以下是解析为JSON的数据
//数据是从callAjaxIndex.php文件返回的
});
});您可以试试这个

$(document).on('change','da',function(){
$.post(“callAjaxIndex.php”,{'method':1,'id':$(this.val()},函数(数据){
var d=$.parseJSON(数据);//以下是解析为JSON的数据
//数据是从callAjaxIndex.php文件返回的
});

});您可以通过将函数更改为以下内容来查找错误:

//other code
error: function(data)
{
    console.log(data.responseText) 
}
//other code
这将告诉您它失败的原因,这可能是一般性的,但比“错误”要好

另请注意:

  • 这是通过电话完成的,所以请原谅任何错误
  • 我宁愿这被当作一个评论,直到我可以得到一台机器,以帮助更多:)

  • 通过将函数更改为以下内容,可以发现错误:

    //other code
    error: function(data)
    {
        console.log(data.responseText) 
    }
    //other code
    
    这将告诉您它失败的原因,这可能是一般性的,但比“错误”要好

    另请注意:

  • 这是通过电话完成的,所以请原谅任何错误
  • 我宁愿这被当作一个评论,直到我可以得到一台机器,以帮助更多:)


  • 你能分享你的错误吗?我不知道,在哪里读错误。我是阿贾克斯的新手。顺便说一下,我的意思是它运行内部所有错误:function(){…}您可以通过firefox inspect元素检查网络和实际发生的情况。我使用chrome,控制台中没有显示任何内容。。我将立即下载firefox如果您通过teamviewer共享您的计算机,那么我可以为您修复它。您可以共享您的错误吗?我不知道,从哪里读取错误。我是阿贾克斯的新手。顺便说一下,我的意思是它运行内部所有错误:function(){…}您可以通过firefox inspect元素检查网络和实际发生的情况。我使用chrome,控制台中没有显示任何内容。。现在我将下载firefox如果您通过teamviewer共享您的计算机,那么我可以为您修复它,这有什么帮助?我需要返回代码中提到的json代码,作为json进行解析。请在Object.success((索引):41)在Object.fire(jQuery-1.12.4.js:9840)在完成时(jQuery-1.12.4.js:9840)检查uncaught SyntaxError:Unexpected token<在JSON.parse()在Function.jQuery.parseJSON(jQuery-1.12.4.js:9011)在JSON位置0处的JSON中在XMLHttpRequest.callback(jquery-1.12.4.js:10311)中,这就是结果。似乎从服务器接收的数据也有html代码。如果您可以在网络部分下签入开发者工具,您可以找到响应数据。这有什么帮助?我需要返回代码中提到的json代码,作为json进行解析。请在Object.success((索引):41)在Object.fire(jQuery-1.12.4.js:9840)在完成时(jQuery-1.12.4.js:9840)检查uncaught SyntaxError:Unexpected token<在JSON.parse()在Function.jQuery.parseJSON(jQuery-1.12.4.js:9011)在JSON位置0处的JSON中在XMLHttpRequest.callback(jquery-1.12.4.js:10311)中,这就是结果。似乎从服务器接收的数据也有html代码。如果您可以在网络部分下签入开发者工具,您可以找到响应数据。