I am using ajax query from jquery. I have 3 module or 3 file. 1st is php file of represent data , 2nd is js file where all javascipt and ajax code is written and 3rd one is my bussiness logic php file.
I call a javascript function from my 1st file i.e show(id). After that this function in js file call ajax
function show(id){
// validation / client side.
// function - lll to stringmatch - name proper.
$.ajax({
type : "POST",
cache : true,
dataType: "json",
url : "a.php",
data : {
proid:id
},
success: function(data) {
alert(data);
//$("#match_item_display").html(data);
}
});
}
and my a.php file return json 2 dimensional array... After that i want to use json 2 dimmentional array in php or 1st page.
Please help me guys...
4 Answers 4
Yes, the data will show as [object Object] from an alert().
If you want to analyze the data as it has returned you should log it to the web console with console.log(data); instead.
You're then free to use the data in the callback. Provided you returned a json encoded object from PHP, you don't even have to massage the data. Just use data.prop1, data.prop2... etc
Comments
you cannot view the content of an object or array using alert.
if you use google chrome or firefox with firebug plugins, use console.log(data); instead of alert(data);
press F12 just before you load the page to enable / show developer toolbar, you should be able to see the object in the console of the firebug or chrome.
good luck.
2 Comments
var jsonData = [{"data":"oneone"},{"name":"onetwo"}];
for(var a in jsonData) {
if(jsonData.hasOwnProperty(a)) {
for(var b in jsonData[a]) {
if(jsonData[a].hasOwnProperty(b)) {
alert(jsonData[a][b]);
}
}
}
}
3 Comments
Loop the json array
function show(id){
// validation / client side.
// function - lll to stringmatch - name proper.
$.ajax({
type : "POST",
cache : true,
dataType: "json",
url : "a.php",
data : {
proid:id
},
success: function(data) {
var str = '<div><ul>';
for (i=0;i<data.length;i++){
str += '<li>'+data[i]['json_index']+'</li>';
}
str +='</ul></div>';
}
});
}
$(document).ready(), it should work fine for you. Can you elaborate on After that i want to use json 2 dimmentional array in php or 1st page.?