我这两天在学习ajax,但总是不成功,下面是具体的前后端代码 前端:
<button onclick = "mySubmit()">登录</button>function mySubmit(){ var params = { "user_id": "testid", "password": “testpwd” }; $.ajax({ url: '/login’, type: 'post’, data: params, datatype: 'json’, success: function(){ allert(‘hai’); }, error: function(XMLHttpRequest, textStatus, errorThrown){ alert(XMLHttpRequest + ‘#’ + textStatus + ‘#’ + errorThrown); }, complete: function(a,b){ alert(a + ‘complete#’ + b); } }); }; 后端: app.post('/login’,user.doLogin); (下面的exports是在user里面的) exports.doLogin = function(req,res){ console.log(“come here " + req.body.user_id + “#” + req.body.password); res.writeHead(200, { 'Content-Type’: 'application/json’, ‘Access-Control-Allow-Origin’ : ‘*’ }); res.json({"success":1}); res.end(); }; 在前端点击button后,后端命令行中有输出"come here testid # testpwd” 但前端总是回调error方法,alert框里是[object object] #error# 然后再调用complete方法,alert框里是[object object] #error 求问这是哪里写错了啊? 我是新手,请大家多指教!