Jsonp / Ajax返回 - 语法错误:无效标签

时间:2021-03-03 23:02:45

My code looks like below.. not sure what is the problem..

我的代码如下所示..不确定是什么问题..

<script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

<script type="text/javascript">
jQuery.getJSON("http://dev9.edisbest.com/json.php?symbol=IBM&callback=?", 
function(data) {
    alert("Symbol: " + data.symbol + ", Price: " + data.price);
});
</script>

My JSON.PHP page code is below

我的JSON.PHP页面代码如下

<?
header("Content-Type: application/json");
print json_encode(array("symbol" => "IBM", "price" => 91.42));
?>

2 个解决方案

#1


1  

Looks like the JSON string returned from dev9.edisbest.com server is invalid.

看起来dev9.edisbest.com服务器返回的JSON字符串无效。

Now returned:

{symbol: 'IBM', price: 91.42}

which is invalid. Consider having the following lines in your PHP back end:

这是无效的。考虑在PHP后端使用以下行:

<?php
$json = json_encode(array(
    "symbol" => "IBM",
    "price" => 91.42
));

header("Content-Type: application/json");
print $_GET['callback'] . "(" . $json . ")";
?>

#2


0  

Try this: alert("Symbol: " + data['symbol'] + ", Price: " + data['price']);

试试这个:alert(“符号:”+数据['符号'] +“,价格:”+数据['价格']);

#1


1  

Looks like the JSON string returned from dev9.edisbest.com server is invalid.

看起来dev9.edisbest.com服务器返回的JSON字符串无效。

Now returned:

{symbol: 'IBM', price: 91.42}

which is invalid. Consider having the following lines in your PHP back end:

这是无效的。考虑在PHP后端使用以下行:

<?php
$json = json_encode(array(
    "symbol" => "IBM",
    "price" => 91.42
));

header("Content-Type: application/json");
print $_GET['callback'] . "(" . $json . ")";
?>

#2


0  

Try this: alert("Symbol: " + data['symbol'] + ", Price: " + data['price']);

试试这个:alert(“符号:”+数据['符号'] +“,价格:”+数据['价格']);