2 回答

TA貢獻1802條經(jīng)驗 獲得超4個贊
我也遇到同樣的問題,后來用firebug查看網(wǎng)絡請求發(fā)現(xiàn)js沒有問題,問題在于ajax返回的數(shù)據(jù)錯誤,格式是<script
type='text/javascript'> ... ...
</script>所以報錯顯示的是返回的串的第一個字符“<”

TA貢獻1816條經(jīng)驗 獲得超4個贊
我簡單說下,
ajax 返回數(shù)據(jù)為空,或返回的html頁面,但返回到這個頁面的有些參數(shù)為空,就會報此錯誤.
下面是我的代碼
@RequestMapping("/exam_type")
public String examination_type(
@RequestParam(defaultValue= "0") Integer category_organization,
@RequestParam(defaultValue= "0") Integer category_region ,
@RequestParam(defaultValue= "0") Integer category_grade ,
@RequestParam(defaultValue= "0") Integer category_subject,
@RequestParam(defaultValue= "1") Integer page,
Model model, HttpSession session){
practiceAjaxPageReloadService.examination_type(category_organization,category_region,category_grade,category_subject, model ,session,page);
return "front/on_line_practice/ajax_page_reload";
}
我這個是spring + spring mvc + mybatis maven 項目
可以看到我 return 是一個頁面
ajax 代碼
$.post('/exam_type',{category_organization:id,category_region:category_region,category_grade:category_grade,category_subject:category_subject},function(data){
$("#tikuUl").html(data)
},'html');
后臺return 的頁面 實際上就是這個 data ,只是一個變量而已,只是習慣用data
看 這個實現(xiàn)類
@Override
public void examination_type(Integer category_organization,Integer category_region ,Integer categor ......){
.................................................
...................................................
...................................................
model.addAttribute("page", page);
model.addAttribute("category_organization", category_organization);
model.addAttribute("category_region", category_region);
model.addAttribute("category_grade", category_grade);
model.addAttribute("category_subject", category_subject);
}
if(${page.totalPages} > 0){
}
${page.totalPages} 后臺沒有傳到前臺這個值就報了這個錯,
報這個錯的原因應該會有很多情況,我這個也許只是一葉扁舟
大家可以看到我用model.addAttribute 返回很多東西到頁面 ,當頁面接收不到這些參數(shù)時就會報 錯,我也是找了好一會 才找到
添加回答
舉報