Jquery Post与JSON响应工作

时间:2014-12-31 04:50:45

标签: javascript php jquery json

我有一个jQuery Post到PHP页面,生成一个JSON响应。它成功生成了JSON,因为我显示了整个响应。但就我而言,我无法提醒它。任何想法都赞赏。谢谢。 JSON看起来像:

[{"Part_Field":"Part_Note:3","Part_Value":"ValueofPart"},{"Part_Field":"Ft_In:3","Part_Value":"12"}, ...

jQuery的:

 $.post('/scripts/update_detail.php' , field_id + "=" + value, function(data){
              var d = document.getElementById("displayjson");
                d.innerHTML = data;

               $.each( data, function( key, value ) {
                  alert( value.Part_Field );
                });


   });

1 个答案:

答案 0 :(得分:0)

你最后忘记了字符串},"json");

更正后的代码应为:

 $.post('/scripts/update_detail.php' , field_id + "=" + value, function(data){
              var d = document.getElementById("displayjson");
                d.innerHTML = data;

               $.each( data, function( key, value ) {
                  alert( value.Part_Field );
                });


   },"json"); // Here, you need to tell jQuery that whatever response
// we are getting from server is a JSON string, in your case, 
//it was considering it as a string.