Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ajax成功错误函数没有';不要在jquery中调用_Javascript_Ajax_Jquery - Fatal编程技术网

Javascript ajax成功错误函数没有';不要在jquery中调用

Javascript ajax成功错误函数没有';不要在jquery中调用,javascript,ajax,jquery,Javascript,Ajax,Jquery,嗨,这是我的密码 <html> <head> <script src="http://code.jquery.com/jquery-1.8.0.min.js"> </script> </head> <body> <form id="foo"> <label for="bar">A bar</label> <input id="bar" name="bar

嗨,这是我的密码

<html>
<head>   
<script src="http://code.jquery.com/jquery-1.8.0.min.js">
</script>
</head>  
<body> 
<form id="foo">

    <label for="bar">A bar</label>
    <input id="bar" name="bar" type="text" value="" />

    <input type="submit" value="Send" />

</form>  
<div id ="onsuccess">      
</div>   
<script>  
// variable to hold request
var request;
// bind to the submit event of our form
$("#foo").submit(function(event){   
    var $form = $(this);
    var serializedData = $form.serialize();
    request = $.ajax({
        url: "a.txt",
        type: "post",
        dataType: "text", 
        data: serializedData,
        success: function(){ 
        console.log("yes, its successful");},
        error : function(){console.log("got an error");}
    });
});

</script>
</body> 
</html>

它确实有效

尝试.完成、.失败和.始终

jQuery1.8中提供了成功和错误回调

弃用通知:jqXHR.success()、jqXHR.error()和 jqXHR.complete()回调从jQuery 1.8开始就不推荐使用。准备 要最终删除它们,请使用jqXHR.done()、jqXHR.fail(), 而jqXHR.always()则相反


需要将此添加到提交处理程序

event.preventDefault()

我不明白为什么要将表单发布到文本文件中?我也可以使用GET..但我想这没有什么区别Hi@daniel powell你想说我必须使用request=$.ajax({url:“a.txt”,type:“POST”,dataType:“text”,data:serializedData,done:function(response,textStatus,jqXHR){console.log(“yes,its successful”);},fail:function(jqXHR,textStatus,errorshown){console.log(“got a error”);});但它并没有再次帮助我,什么都没有发生是的,它工作了……这意味着表单显示了它的固有属性
event.preventDefault()