How to get jSON response into variable from a jquery script

前端 未结 4 1920
小鲜肉
小鲜肉 2020-12-13 15:00

I am having trouble with my jquery script below, this is a basic stripped down version and even it will not work, I have the php file that the jquery script makes a call to

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 15:12

    Here's the script, rewritten to use the suggestions above and a change to your no-cache method.

    'error','comment'=>'test comment here');
    echo json_encode($arr);
    ?>
    
    //the script above returns this:
    {"response":"error","comment":"test comment here"}
    
    
    

    The main issue here was that you had a typo in the JSON you were returning ("resonse" instead of "response". This meant that you were looking for the wrong property in the JavaScript code. One way of catching these problems in the future is to console.log the value of data and make sure the property you are looking for is there.

    Learning how to use the Chrome debugger tools (or similar tools in Firefox/Safari/Opera/etc.) will also be invaluable.

提交回复
热议问题