jquery - send data to php and receive response -
i want send data jquery script file php script file process , receive response, however, response comes content of php file
what ?
this jquery script:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>test</title> <script type="text/javascript" src= "jquery.js"></script> <script type="text/javascript"> function client(name,lastname){ this.name = name; this.lastname = lastname; } $(function(){ var submit = $("#submit"); var clientname = $("#clientname"); var clientlastname = $("#clientlastname"); submit.click(function(){ var client = new client(clientname.val(),clientlastname.val()); alert(json.stringify(client)); $.ajax({ type :'get', url:'save.php', data: {json:json.stringify(client)}, success:function(data){ alert(data); } }); }); }); </script> </head> <body > <div> <label for="clientname" >clientname</label> <input id="clientname" type="text"/> <label for="clientlastname" >clientlastname</label> <input id="clientlastname" type="text"/> <input type="submit" id="submit" value="submit"/> </div> </body>
this php script:
<?php $value = json_decode($_get['json']); echo $value['clientname']; ?>
this in return :
what need echoed variable rather contents of php file?
check whether php can compiled in localhost suggested nirazul.
access json
values in php make use of ->
. modified script below
<?php $value = json_decode($_get['json']); echo $value->name; // or $value->lastname ?>
Comments
Post a Comment