AJAX Return Problem from data sent via jQuery.ajax
Posted
by Anthony Garand
on Stack Overflow
See other posts from Stack Overflow
or by Anthony Garand
Published on 2010-03-08T19:47:04Z
Indexed on
2010/03/08
19:51 UTC
Read the original article
Hit count: 1257
I am trying to receive a json object back from php after sending data to the php file from the js file.
All I get is undefined.
Here are the contents of the php and js file.
data.php
<?php
$action = $_GET['user'];
$data = array( "first_name" => "Anthony", "last_name" => "Garand", "email" => "[email protected]", "password" => "changeme");
switch ($action) { case '[email protected]': echo $_GET['callback'] . '('. json_encode($data) . ');'; break; }
?>
core.js
$(document).ready(function(){
$.ajax({ url: "data.php",
data: {"user":"[email protected]"},
context: document.body,
data: "jsonp",
success: function(data){renderData(data);}
});
});
function renderData(data) { document.write(data.first_name); }
© Stack Overflow or respective owner