Join the Stack Overflow Community
Stack Overflow is a community of 6.2 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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...

share|improve this question
    
Here is alert data show only [object Object]...so on.. – Rahul Gupta Feb 15 '12 at 5:29
    
Provided you wrap that in $(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.? – Jordan Arseno Feb 15 '12 at 5:32
    
my index.php page have html code and php code...i call javascipt function from index page this javascript function on $(document).ready after that call javascipt function its call ajax. This ajax requestion is go on a.php and a.php return 2D array here i use echo json_encode($arr); $arr is 2D array.In ajax success funtion its return json and i want use this 2d json in index.php... – Rahul Gupta Feb 15 '12 at 5:35
    
Is your problem accessing the array? – busypeoples Feb 15 '12 at 5:42
    
Yes i have json return in data but i want this array in javasciprt..Is this possible..??? – Rahul Gupta Feb 15 '12 at 5:44

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

share|improve this answer

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.

share|improve this answer
    
I believe F12 is for FF and IE only. See here for details. :) – Jordan Arseno Feb 15 '12 at 5:47
    
Yes, F12 only works in FF (if you have firebug plugins), IE and Chrome. I've mention FF and Chrome in my answer, but I forgot mentioning IE. Thanks, Jordan. – Andrew Leonheart Mar 7 '12 at 6:58
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]);
            }
        }
    }
}
​    ​
share|improve this answer
    
Its show undifined my json data is like this var jsonData = [{"data":"oneone"},{"data":"onetwo"}] – Rahul Gupta Feb 15 '12 at 6:02
    
var jsonData = [{"data":"oneone"},{"name":"onetwo"}]; alert(jsonData[0].data); – busypeoples Feb 15 '12 at 6:09
    
how to iterate this jsonData on index.php in html code..please explain me... thanx for suggetion.. :) – Rahul Gupta Feb 15 '12 at 6:21
    
Updated the example. – busypeoples Feb 15 '12 at 6:30

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>';




        }
    });



}
share|improve this answer
    
how to use this data object on index.php how to implement..please discribe..thanx for suggestion.. :) – Rahul Gupta Feb 15 '12 at 6:22
    
index.php or index.html ???? – coolguy Feb 15 '12 at 6:31
    
do you want to give the json values to some 'html' elements in the index.php file ? – coolguy Feb 15 '12 at 6:32
    
index.php file but i want its iterate in client machine means in javascript.. – Rahul Gupta Feb 15 '12 at 6:33
    
Check the update you will have a unordered list having all the elements just put it in your page using jquery like this $('#somecontanerid').html(str); – coolguy Feb 15 '12 at 8:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.