views:

25

answers:

1

I have this :

 p['record_id'] = 2;
 $('#trcode').val($(this).load('url_to_PHP_methode',p,function(str){}));

The value returned from PHP method is like this -> "Just String"

In firebug, there is correct response value, "Just String", but in text input with ID #trcode it shows [object Object].

So, my question is: How to show the correct return value just like Firebug "Just String"?

A: 

.load() is for loading content into an element, it returns the jQuery object (for chaining), which is why you see the "[object Object]" string you do now.

Instead, what you want is to use $.get() and use the response, like this:

$.get('url_to_PHP_methode', function(str) {
  $('#trcode').val(str);
});
Nick Craver
aahh thanks u nick, work now, GBU
Neutron Star
hi nick, if u don't mind i wanna ask to u again,hehe
Neutron Star
@Neutron - about?
Nick Craver
now the problem is, when I ubmit the form the value of text input #trcode is empty, I check in firebug when I call the function tht i made before is still empty, any suggestion nick ?
Neutron Star
@Neutron - AJAX operations take a bit of time to complete, so you can't do this and submit instantly, you'd need to submit *after* the `.val()` call in the callback function above. The `$.get()` method fires an AJAX request, and *when it comes back* the value gets populated. The reason is the server responding takes some time.
Nick Craver
nick, sorry for disturbing u, I found the problem, tnx brother work now, GBU
Neutron Star
@Neutron - welcome! be sure to accept answers to resolved questions via the check-mark beside the one that best helped :)
Nick Craver