I've been working on a project and I recently came across this strange Jquery behaviour!
(我一直在从事一个项目,最近遇到了这种奇怪的Jquery行为!)
Code Snippet
(代码段)
$("#form_1").submit(function (event){
event.preventDefault();
response = sendform('form_1', '../php/signup-01.php', 'POST', '');
console.log(response.responseText);
});
sendform()
(sendform())
function sendform(id, location, method, extrapars) {
response = $.ajax({
url : location ,
data : $("#"+id).serialize() + extrapars ,
cache : false ,
processData : false ,
type : method ,
success : function (successmsg) {
return successmsg;
}
});
return response;
}
So basically I'm trying to send some form data through a pre-defined function, but when I try to log it response in my console it says Undefined
.
(因此,基本上,我试图通过预定义的函数发送一些表单数据,但是当我尝试在控制台中记录响应时,它显示为Undefined
。)
I know that this is an JS Object, so I even tried using Console.log(response[responseText])
. (我知道这是一个JS对象,所以我什至尝试使用Console.log(response[responseText])
。)
When I try to log the complete object, Console.log(response)
, Its something LIKE
(当我尝试记录完整的对象Console.log(response)
,有点像)
abort: ? ( statusText )
always: ? ()
catch: ? ( fn )
done: ? ()
fail: ? ()
getAllResponseHeaders: ? ()
getResponseHeader: ? ( key )
overrideMimeType: ? ( type )
pipe: ? ( /* fnDone, fnFail, fnProgress */ )
progress: ? ()
promise: ? ( obj )
readyState: 4
responseText: "Unused OTP in DB!"
setRequestHeader: ? ( name, value )
state: ? ()
status: 200
statusCode: ? ( map )
statusText: "OK"
then: ? ( onFulfilled, onRejected, onProgress )
__proto__: Object
So any help with that would be helpful for me.
(因此,对此的任何帮助将对我有所帮助。)
Thanks in advance! (提前致谢!)
ask by Arag Aggrawal translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…