Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.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
如何在jquery中正确检索php数组_Php_Jquery_Ajax - Fatal编程技术网

如何在jquery中正确检索php数组

如何在jquery中正确检索php数组,php,jquery,ajax,Php,Jquery,Ajax,我正在尝试从ajax调用中获取变量:error、armount\u payout、this.result1、this.result2、this.result3,这是我到目前为止的代码,但它返回了一个错误 Uncaught SyntaxError: Unexpected token < jquery.js:25_ .parseJSON jquery.js:25 Game.restart slots.js:188 (anonymous function) slots.js:127 _.even

我正在尝试从ajax调用中获取变量:error、armount\u payout、this.result1、this.result2、this.result3,这是我到目前为止的代码,但它返回了一个错误

Uncaught SyntaxError: Unexpected token < jquery.js:25_
.parseJSON jquery.js:25
Game.restart slots.js:188
(anonymous function) slots.js:127
_.event.dispatch jquery.js:25
q.handle jquery.js:24
和我的jquery代码:

    data=$.ajax({
        type: "POST",
        url: "../php/runslotsgame.php",
        data: "address=" + address,
        dataType: 'json',
        async: false
    }).responseText;

    var dataArray = jQuery.parseJSON(data);
            error = dataArray [0];
            armount_payout = dataArray [1];
            this.result1=dataArray [2];
            this.result2=dataArray [3];   
            this.result3=dataArray [4]; 
    console.log("yay"); 
而且我的控制台里也没有yay


有人看到我做错了什么吗?

别忘了在ajax响应中添加Content Type=application/json头:

Content-Type = application/json
另外,不确定您使用的是哪个版本的jQuery,但是您需要检查回调,因为.ajax是一个异步函数

$.post(url,{address:address},function(data){
    var dataArray = data;
    //where you need to use your data array
});

直接用浏览器点击JSON生成URL并检查输出。您的错误消息表明JSON无效

您可以使用检查工具来检查它是否存在问题

$.post(url,{address:address},function(data){
    var dataArray = data;
    //where you need to use your data array
});