3

My .php code in a file "fetchvalues.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?

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

3 Comments

It is showing the entire record in the alert box not that particular column value.
@RPK, did you change your PHP to match what I posted? You were using . and I used , instead.
Awesome! Good luck with your project!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.