天天看點

JS中Ajax的success元素不執行

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注解

JS中Ajax的success元素不執行

就OK了,還不行的話檢查ajax位置是不是寫了dataType,沒傳回值可以不寫

入門尚淺,望有錯大家及時糾正,希望能幫到你們 ^ v ^