开发者

Get values from JSON encoded array string

My .php code in a file "fetchv开发者_如何学运维alues.php" looks like this:

echo json_encode(array($PostedDate.Places.$Company.$Designation.$ProjectDetails.$DesiredCandidate.$HRName.$HRContact.$Email));

This file is called by another file and the calling function looks like:

$(document).ready(function() {
  $("#Edit").click(function() {
    $.getJSON("fetchvalues.php?UpdateRecordID=" + $.cookie('UpdateRecordID'),
      function(data) {
        // Data retrieved in concatenated form. So we will break it and store values in array.
        var concatenatedvalues = new Array();
        concatenatedValues = data;
        alert(concatenatedValues);
      });
  });
});

The data is being returned successfully, but I am not following how get each array element through javascript. What modifications are needed in the above code?


Update I just reread your question and it looks like you intentionally concatenated the values. Since you are using json_encode it would be much better to send the values as an array, and simply access it in JavaScript.

echo json_encode(array($PostedDate, $Places, $Company, $Designation, $ProjectDetails, $DesiredCandidate, $HRName, $HRContact, $Email));

Then in JavaScript they would be accessed like this:

alert(data[1]); // Would alert the value of $Places
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜