Click here to Skip to main content
15,924,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I have a jquery function that receives a value from a php function now it just prints Object out to the screen instead of the actual value

this is my jquery function
JavaScript
function loadRep(){
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: '{$ajaxUrl}' + '&act=loadRep',
                        data: 'storeId={$storeId}',
                        success: function(data){
							 $('#rep_name').html('<span id="rep_name">' + data['html'] + '</span>');
                        }
					});
            }

this is my php controller function
PHP
public function loadRep($dealerId,$userType=null){
        $app = Wow_Application::getInstance();
		$output= false;
        $dealerId = Wow_Utility::getGPValue('storeId');
        if($dealerId){
			$dealer = new Wow_Dealerstore_Model;
			$dealer->load($dealerId);
			$rep = $dealer->loadRep($dealerId,$userType);
			$output['html'] = $rep;
		}
		
		$this->document->loadJson(Zend_Json::encode($output));
	}

I would just like it to display the value instead of the word object.

Thanks
Posted
Updated 3-Jan-12 4:11am
v2

1 solution

nathan666 wrote:
I have a jQuery function that receives a value from a PHP function


It is pretty difficult to answer a question which starts from the wrong idea expressed in the sentence shown above. This is not what really happens.

PHP works on the server side only, jQuery — on the client side only. PHP generates a whole HTML page and the server sends it to the client side in HTTP response to client's previous request. The client side loads the page; and the browser tries to run the scripts, including your jQuery script. In most cases, you need to handle "document ready" event using $(document).ready(function() { /*...*/ } in your jQuery script. Now, your script never receive any values from any PHP functions; instead, the result of PHP execution is the generation of the whole HTML page including your scripts. Even though some part of this text is parametric, for a script this is nothing but an embedded static text.

If you need to send a "POST", "GET" or any other HTTP request from the jQuery, you can use jQuery Ajax methods like jQuery.post(), jQuery.get(), etc., see http://api.jquery.com/category/ajax/[^].

When a request is sent via Ajax, the process is repeated from scratch. The only result of the previous calculations which is preserved is the content of the request. If you need anything else, you need to use PHP session management, see http://php.net/manual/en/ref.session.php[^].

I think if you put these considerations all together, you will explain the problem correctly to yourself and will see how to solve it.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900