Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Return value of $.post

    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:
    Code:
    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:
    Code:
    function fetch_address(object_id)
    {
    	$.post("<?=site_url();?>/core_page/client/getFlow", { object_id: object_id, language_short: '<?=$this->session->userdata('language_short');?>' },
       	function(data)
       	{
    		$('#object_'+object_id).slideDown('fast');
    	   	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!

    Regards,
    Smilie
    Last edited by smiile; 10-29-2010 at 01:38 PM.

  • #2
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Regards,
    Smilie


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •