Friday, 15 May 2015

javascript - How to code php file in ajax request to the server using JSON? -



javascript - How to code php file in ajax request to the server using JSON? -

i have next ajax request code

$.getjson('getinfo.php' , 'user=bob', callback );

in getinfo.php how grab user=bob ? thanks.

in getinfo.php how grab user=bob?

$.getjson() send get request data, 'user=bob', included in query-string:

getinfo.php?user=bob

these can accessed by name $_get:

class="lang-php prettyprint-override"><?php $user = $_get['user']; echo json_encode($user); // "bob" ?>

for getjson() request succeed, response need valid json, json_encode() can used generate.

javascript php jquery ajax json

No comments:

Post a Comment