【发布时间】:2011-03-16 14:18:44
【问题描述】:
我的 AJAX 脚本都运行良好,并且成功功能正在运行,但脚本仍然会出现错误消息。我已经确定问题是 parseerror。我还没有确定为什么会发生这种情况以及如何阻止它。
AJAX
var dataString = 'title=' + title + '&price=' + price + '&duration=' + duration + '&dives=' + dives + '&hire=' + hire + '&date=' + date + '¤cy=' + currency + '&cost=' + cost + '&supplier=' + supplier;
$.ajax({
type: 'POST',
url: '<?php echo $thisposturl?>?catadd',
data: dataString,
beforeSend: function() {
$('#loadwheel-new').html('<img id="BKloader" src="http://www.divethegap.com/update/z-images/structure/icons/ajax-loader.gif" alt="" width="30" height="30"/>');
},
error: function() {
$('#loadwheel-new').html('lkk');
},
dataType:'json',
success: function(data) {
$('#CollapsiblePanel' + data.CATid).load('<?php echo $thisposturl?> #' + data.CATid);
;
} });
PHP
$title = $_POST['title'];
$CATid = $the_post_id;
$date = get_the_time('Y-m-d');
$price = $_POST['price'];
$duration = $_POST['duration'];
$dives = $_POST['dives'];
$hire = $_POST['hire'];
$currency = $_POST['currency'];
$cost = $_POST['cost'];
$supplier = $_POST['supplier'];
echo json_encode( array('title'=>$title, 'CATid'=>$CATid, 'date'=>$date, 'price'=>$price, 'duration'=>$duration, 'dives'=>$dives, 'hire'=>$hire, 'currency'=>$currency, 'cost'=>$cost, 'supplier'=>$supplier));
【问题讨论】:
-
解析错误发生在服务器端还是客户端?
-
服务器端。我认为这与 JSON 有关
-
您从服务器收到的结果是什么?你能用firebug复制粘贴吗?您应该能够查看从服务器收到的响应。
-
我最近在 ColdFusion 中发生了这种情况:我的问题是附加信息与 JSON 一起返回,所以即使它在创建时是格式正确的 JSON,也无法正确解析. (我打开了页面级调试,因此包含了调试信息。)
标签: javascript php ajax json