On Aug 6, 1:23 pm, mohsin <[EMAIL PROTECTED]> wrote:
> thnx for ur help but that is hard coded values from jQuery.

i don't understand what you mean - what is hard coded? You can pass
any arguments you want to $.getJSON() and they will be passed on to
the PHP script:

$.getJSON( 'myscript.php', {foo:'bar',bar:'foo'}, function(json)
{...});

That is the same as calling:

http://myserver/path/to/myscript.php?foo=bar&bar=foo

and the result is expected to be JSON code.

> i need to
> pass values from php to jquery $.get function as i need them in ajax
> file called by $.get function. as we used before like this
> onclick="call_ajax('<?=$userid?>',<?=$productid?>)"
> how can i do this with jQuery

That's what i'm saying: you can't pass variables directly from PHP to
JavaScript (whether you're using jQuery or mootools or any other
toolkit). PHP is executed on the server and JS is executed on the
client (in the browser). The only path of communication between PHP
and JS is for JS to make a GET or POST request to a PHP script. From
such a request, a JS script can pass an arbitrary number of key/value
pairs to the PHP script. The PHP script, on the other hand, returns a
SINGLE response and sends an arbitrary amount of content (any type of
data) back to the requesting javascript (PHP has no way of knowing
that the request came come from javascript). If the PHP returns
something which the JS can directly read (e.g. JSON) then PHP can
indirectly communicate with the JS code.

Alternately, when your PHP code generates a web page it can embed JS
calls, as you demonstrated:

... onclick="call_ajax('<?=...?>')" ...

And you can fetch data from PHP using $.get(), $.getJSON(), or similar
functions. If your PHP code can generate JSON data then it is trivial
to use the returned data from JavaScript.


Reply via email to