JQuery的AJAX莫名其妙parseerror [英] JQuery AJAX inexplicable parseerror
本文介绍了JQuery的AJAX莫名其妙parseerror的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的AJAX脚本都运行完美,成功的功能正在工作但剧本依然打的错误消息。我已经确定,问题是parseerror。我还没有确定是为什么发生这种情况,以及如何阻止它。
AJAX
VAR dataString ='标题='+标题+'和;价格='+价格+'和;持续时间='+时间+'和;潜水='+潜水+ &功放;聘请='+雇用+'和;日期='+日期+'和;货币='+货币+'和;成本='+成本+'和;供应商='+供应商;
$阿贾克斯({
键入:POST,
网址:'?< PHP的echo $ thisposturl> catadd?,
数据:dataString,
beforeSend:函数(){
$('#loadwheel新)HTML('< IMG ID =BKloaderSRC =http://www.divethegap.com/update/z-images/structure/icons/ajax-loader.gif中高音=宽度=30高度=30/>');
},
错误:函数(){
$('#loadwheel新)HTML(李锦记)。
},
数据类型:JSON,
成功:功能(数据){
$('#CollapsiblePanel'+ data.CATid).load('<?PHP的echo $ thisposturl>?#+ data.CATid);
;
}});
PHP
$标题= $ _ POST ['标题'];
$ CATID = $ the_post_id;
$日期= get_the_time('Y-M-D');
$价格= $ _ POST ['价格'];
$时间= $ _ POST ['时间'];
$潜水= $ _ POST ['潜水'];
$聘请= $ _ POST ['雇佣'];
$货币= $ _ POST ['货币'];
$成本= $ _ POST ['成本'];
$供应商= $ _ POST ['供应商'];
回声json_en code(阵列('标题'=> $标题,'CATID'=> $ CATID,'日期'=> $日期,'价格'=> $的价格,'时间'=&GT ; $时间,'潜水'=> $潜水,'租用'=> $聘请,货币=> $货币,'成本'=> $成本,供应商=> $供应商)) ;
解决方案
输出的JSON之前尝试清理缓存在服务器端使用 ob_clean
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));
解决方案
Try clean buffer on server side with ob_clean
before output your JSON
这篇关于JQuery的AJAX莫名其妙parseerror的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文