JS中Ajax的success元素不執行
阿新 • • 發佈:2020-12-12
技術標籤:ajax踩過的坑jqueryjavascriptjavaspringspring boot
JS中Ajax的success元素不執行
感謝大哥劉文華。
問題程式碼如下:
$.ajax({
type : "POST",
url : "/student/edit",
data : obj,
success : function(){
alert("修改成功" );
first();
},
error : function() {
alert("修改失敗");
}
})
檢視對應 url 路徑的後臺程式碼【controller】層
@Controller
@RequestMapping("/student")
public class StudentController {
@Autowired
private StudentService studentService;
@RequestMapping("")
public String tiaozhuan(Model model) {
return "/student/student.html";
}
@RequestMapping("/edit")
public void edit(Student student){
studentService.edit(student);
}
@RequestMapping("/list")
@ResponseBody
public List<Student> list(Integer num){
return studentService.list(num);
}
在這個位置 新增@ResponseBody註解
就OK了,還不行的話檢查ajax位置是不是寫了dataType,沒返回值可以不寫
入門尚淺,望有錯大家及時糾正,希望能幫到你們 ^ v ^