views:

71

answers:

1

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?

+3  A: 

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
Doug Neiner
It is showing the entire record in the alert box not that particular column value.
RPK
@RPK, did you change your PHP to match what I posted? You were using `.` and I used `,` instead.
Doug Neiner
Ohh. I am checking.
RPK
Thanks it worked. I didn't check that.
RPK
Awesome! Good luck with your project!
Doug Neiner