My AJAX scripts are all functioning perfectly and the success function is working yet the script still hits the error message. I have determined that the problem is parseerror. What I have not determined is why this is happening and how to stop it.
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之前,尝试使用ob_clean
在服务器端清理缓冲区
I ran into this when calling $.getJSON, but I think it comes down to the same thing, malformed JSON. I got around it by wrapping my json parsing in a JavaScript try/catch.
Have tried this instead?
var dataString = {
'title': title,
'price': price,
'duration': duration,
'dives': dives,
'hire': hire,
'date': date,
'currency': currency,
'cost': cost,
'supplier': supplier
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.