繁体   English   中英

jQuery AJAX莫名其妙的parseerror

[英]JQuery AJAX inexplicable parseerror

我的AJAX脚本均正常运行,成功功能正在运行,但脚本仍然出现错误消息。 我确定问题出在parseerror。 我还不确定这是为什么发生以及如何阻止它。

AJAX

var dataString = 'title=' + title + '&price=' + price + '&duration=' + duration + '&dives=' + dives + '&hire=' + hire + '&date=' + date + '&currency=' + 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之前,尝试使用ob_clean在服务器端清理缓冲区

我在调用$ .getJSON时遇到了这个问题,但是我认为它归结为同一件事,即格式错误的JSON。 我通过将json解析包装在JavaScript try / catch中来解决此问题。

试过了吗?

var dataString = {
    'title': title,
    'price': price,
    'duration': duration,
    'dives': dives,
    'hire': hire,
    'date': date,
    'currency': currency,
    'cost': cost,
    'supplier': supplier
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM