View Full Version : jQuery Return value of $.post

10-29-2010, 01:22 PM
Hi to all,

Could someone please point me in the right direction regarding following:

PHP page with a <a></a> link.
Once clicked on the link, JS function is called which triggers $.post to call remote PHP file and get data.

Remote PHP files does some DB queries and returns PHP Object.
Only way I have achieved to return data to JS is:

echo json_encode(array('some_var'=>$object->some->var_data);

I can do echo json_encode(array('some_var'=>$object);
In this case JS receives [object Object] (which is correct).

Now, the question:
How can I convert this return data to something PHP usefull?
It would be 'not done' to have to write 75+ lines of printing JS [object Object] to screen :(

At this moment I have:

function fetch_address(object_id)
$.post("<?=site_url();?>/core_page/client/getFlow", { object_id: object_id, language_short: '<?=$this->session->userdata('language_short');?>' },
document.getElementById('object_'+object_id+'_data').innerHTML = data.object_id;
}, "json");

However, this shows only 1 variable out of 75 from object (variable object_id).

My point is to (if possible) convert data.object_id in the PHP variable and then I can loop it and present data.

Thanks in advance!


10-29-2010, 02:12 PM
Oke, after digging into Google, I found out (in examples) that most people prepare full HTML in the PHP and then send ready HTML back to JS.
JS then simply puts in somewhere on a page.

This, technically will work. But isn't there a 'neater' solution? :)

What I actually need is to transform JS return data to PHP var.