我试图用JS / Ajax更新表。
我的Ajax请求:
$.ajax({
type: "GET",
url: 'http://192.168.122.104:8001/controllers/updateList.php?',
data: "query=" + query + "&" + zpeaktype + "year=" + pickedyear,
dataType: 'html',
contentType: "application/x-www-form-urlencoded;charset=UTF-8",
cache: false,
success: function(response)
{
$("#current_picked_year").html(" "+pickedyear);
alert(response[184]+""+response[185]+""+response[186]+""+response[187]+""+response[188]);
var ajaxdata = JSON.parse(response);
$(".table-event").find("#eventnamefield").text(ajaxdata.lang);
});
当我的Ajax请求完成后,错误如下:
" SyntaxError:JSON.parse:在JSON数据的第1行第186行的JSON数据之后出现意外的非空白字符"
我的JSON数据(由PHP脚本返回):
{"language":"breton","organizer":"zpeaktest","eventname":"A vos mousses","eventtype":"party","eventdayname":"Mardi","eventdaynumber":"26","eventmonthname":"juillet","eventtime":"14:30"},{"language":"autre","organizer":"demozpeak","eventname":"Aperotest","eventtype":"party","eventdayname":"Samedi","eventdaynumber":"30","eventmonthname":"juillet","eventtime":"20:30"},{"language":"autre","organizer":"demozpeak","eventname":"March\u00e9 des lices","eventtype":"party","eventdayname":"Lundi","eventdaynumber":"15","eventmonthname":"ao\u00fbt","eventtime":"12:45"}
也许(我猜),它可能是":" " 12:45"例如,但我不知道如何逃避它......
编辑:谢谢,在其他ajax脚本中,我迭代数组添加一些逗号,但最后我不需要这里。
之前:
$lastevent = end($events);
foreach ($events as $event) {
if ($event == $lastevent) {
echo json_encode($event);
} else {
echo json_encode($event).", ";
}
最后,这还不够:
echo json_encode($events);
我不再有错误了,但我问的是推荐什么是contentType / dataType AJAX(发送请求时)?