PHP array to jquery array via JSON

后端 未结 4 1580
执念已碎
执念已碎 2021-01-26 10:37

Im having a little confusion why the following is not working.

get.php



        
相关标签:
4条回答
  • 2021-01-26 11:10

    data contains a string of the JSON, so arr[2] will be the third character in the string. You need to use $.parseJSON(data).

    0 讨论(0)
  • 2021-01-26 11:20

    Your PHP is claiming that the JSON is HTML. You need to explicitly say it is JSON to get jQuery to handle it as such automatically.

    header("Content-type: application/json");
    
    0 讨论(0)
  • 2021-01-26 11:21

    you can't gave the data value to the array.

     $.get("get.php", function(data){
         alert(data[2]);
    }, "json");
    
    0 讨论(0)
  • 2021-01-26 11:30

    Send the json header in php via header('Content-type: application/json'); so jQuery should automatically decode your json data.

    0 讨论(0)
提交回复
热议问题