javascript - jQuery AJAX 莫名其妙的parseerror

标签 javascript php ajax json

我的 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 在服务器端清理缓冲区

关于javascript - jQuery AJAX 莫名其妙的parseerror,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5326594/

相关文章:

javascript - jQuery在Keypress事件上

javascript - 如何通过jquery从sevlet接收信息而不发送请求

javascript - 显示来自 ajax 响应的图像

javascript - 为什么 javascript 在 null 情况下检查类型甚至使用 ==

javascript - 如何在 Flickr API 中仅显示多图像字段中的 1 张图像?

php - 我无法在 ubuntu 16 上将 nginx PHP 版本升级到最新版本

php - 如何在 symfony 重定向中获取 referer url

javascript - 使用dust.js 进行排序功能

java - ClojureScript 编译器如何将 cljs 转换为 Javascript

php - 减少 Foreach 嵌套并替换为 While 循环?