View Single Post
Old 07-18-2012, 06:12 AM   PM User | #1
absoleet
New Coder

 
Join Date: Nov 2009
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
absoleet is an unknown quantity at this point
AJAX/json vars return undefined.

Quite well versed in PHP, newer to AJAX/json/jQuery.

Primary Page

Quote:
<html>
<head>
<script type="text/javascript" src="../resources/jQuery/jquery-1.7.2.min.js"></script>
</head>
<body>

<div id="output">Change me</div>
<?
$data = array("task" => "getuniqueid" ,"id" => "3");
?>
<script id="source" language="javascript" type="text/javascript">

$(function ()
{
$.ajax({
url: '../resources/ajax.api.php',
data: <? echo json_encode($data); ?>,
dataType: 'json',
success: function(data)
{
var task = data[0];
var id = data[1];

//Change div
$('#output').html("<b>Task:</b>"+task+"<b> ID: </b>"+id);
}
});
});

</script>
</body>
</html>

ajax.api.php
Quote:
<?php
chdir('..');
include('includes/global.php');
if($_GET['task']==getuniqueid)
{
$player = new player();
echo json_encode($player->getuniqueID($_GET['id']));
}
?>

Output:


Task:undefined ID: undefined

If I manually visit the page with the parameters passed in the URL,I do get the proper json output.

I have also tried setting the data toUnsuccessful)
"task=getuniqueid&id=3"

Any & all help is appreciated.

Thank you.
absoleet is offline   Reply With Quote