`

【转】jquery ajax submit a form

    博客分类:
  • AJAX
阅读更多

required : jquery.form.js

$(document).ready(function() {
     var options = {
         target:         'server.php',  
         beforeSubmit:   showRequest, 
         success:        showResponse 
         //url:        url          // override for form's 'action' attribute
         //type:       type         // 'get' or 'post', override for form's 'method' attribute
         //dataType:   null         // 'xml', 'script', or 'json' (expected server response type)
         //clearForm: true         // clear all form fields after successful submit
         //resetForm: true         // reset the form after successful submit

         // $.ajax options can be used here too, for example:
         //timeout:    3000
     };

     $('#htmlForm').submit(function() {
         // inside event callbacks 'this' is the DOM element so we first
         // wrap it in a jQuery object and then invoke ajaxSubmit
         $(this).ajaxSubmit(options);

         // !!! Important !!!
         // always return false to prevent standard browser submit and page navigation
         return false;
     });
});

 


// pre-submit callback
function showRequest(formData, jqForm, options) {
     // formData is an array; here we use $.param to convert it to a string to display it
     // but the form plugin does this for you automatically when it submits the data
     var queryString = $.param(formData);

     // jqForm is a jQuery object encapsulating the form element.   To access the
     // DOM element for the form do this:
     // var formElement = jqForm[0];

     alert('About to submit: \n\n' + queryString);

     // here we could return false to prevent the form from being submitted;
     // returning anything other than false will allow the form submit to continue
     return true;
}

// post-submit callback
function showResponse(responseText, statusText)   {
     // for normal html responses, the first argument to the success callback
     // is the XMLHttpRequest object's responseText property

     // if the ajaxSubmit method was passed an Options Object with the dataType
     // property set to 'xml' then the first argument to the success callback
     // is the XMLHttpRequest object's responseXML property

     // if the ajaxSubmit method was passed an Options Object with the dataType
     // property set to 'json' then the first argument to the success callback
     // is the json data object returned by the server

     alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
         '\n\nThe output div should have already been updated with the responseText.');
}

</script>
</head>
<body>
   <form id="htmlForm" autocomplete="on" method="post" action="r.aspx">
       <input  type="submit" value="submit" />
    </form>

</body>
</html>

 

 


server
  
<%
     Response.Write("success");

%>

 

from : http://xinkong1010.iteye.com/blog/866046

分享到:
评论

相关推荐

    jquery-ajax-form-submit.zip_Do You

    Webmaster will activate your member account after checking your files. If you do not want to upload source code,

    jquery.form.js实现将form提交转为ajax方式提交的方法

    主要介绍了jquery.form.js实现将form提交转为ajax方式提交的方法,涉及jQuery插件实现form表单的Ajax提交技巧,非常具有实用价值,需要的朋友可以参考下

    jquery.form.js完美ajax无刷新上传图片插件

    jquery.form.js,这是一个完美提交表单的jquery插件,jquery的ajax无法提交图片,而这个插件可以完美解决,使用方法,将该文件放到jquery后面引入:$('#order_form').ajaxForm(function(a) { var b = eval("(" + a ...

    基于jQuery通过jQuery.form.js插件使用ajax提交form表单

    我简单使用了一下,jQuery Form插件有一下优点: 1.支持提交前验证. 2.支持提交后回调. 3.采用AJAX方式,有很好的用户体验 4.提交方式是灵活.只要指定要提交的form ID即可.想提交那个form.就可提交那个.同时提交...

    jquery ajax表单提交

    表单进行无刷新提交,ajax技术 if (!this.length) { log('ajaxSubmit: skipping submit process - no element selected'); return this; } var method, action, url, $form = this; if (typeof options == ...

    jquery.form.js

    jquery.form.用语ajax提交表单,$("id").submit();可以直接用ajax提交表单,多用于上传图片

    jQuery.Form实现Ajax上传文件同时设置headers的方法

    废话不多说了,关于jquery form实现ajax上传文件的方法,大家参考一下实例代码吧: &lt;span xss=removed&gt;function ajaxSubmitForm() {&lt;/span&gt; var option = { url : cache.batchImport, type : 'POST', ...

    jquery.form.js完美表单提交插件

    jquery.form.js,这是一个jquery插件,jquery的ajax无法提交图片,而这个插件可以完美解决,使用方法,将该文件放到jquery后面引入:$('#order_form').ajaxForm(function(a) { var b = eval("(" + a + ")"); alert...

    jqueryform.js

    // headers:{"ClientCallMode" : "ajax"},//添加请求头部 enctype="multipart/form-data" success: function(data){ if(data.msg=="success"){ alert&#40;"保存成功"&#41;; }else{ alert&#40;"保存失败"&#41;...

    jquery拼接ajax 的json和字符串拼接的方法

    整理文档,搜刮出一个jquery拼接ajax 的json和字符串拼接的代码,稍微整理精简一下做下分享。 jQuery拼接字符串ajax &lt;form id="myForm" action="#"&gt; &lt;input name="name"/&gt; &lt;input name="age"/&gt;...

    jquery ajax提交整个表单元素的快捷办法

    代码如下:function submit(){ var formData=$(“form”).serialize(); $(“#ac”).val(“savesearch”); $.ajax({ type: “POST”, url: “/index.aspx”, processData:true, data:formData, success: ...

    jquery实现ajax提交form表单的方法总结

    方法一: 代码如下:... { var AjaxURL= “../OrderManagement/AjaxModifyOrderService.aspx”; alert&#40;$(‘#formAddHandlingFee’&#41;.serialize()); $.ajax({ type: “POST”, dataType: “html”, 

    Ajax-Spring-MVC-CRUD-form-submit-and-ajax.zip

    Ajax-Spring-MVC-CRUD-form-submit-and-ajax.zip,spring mvc crud应用程序(springmvc、hibernate 4.x、bootstrap 3.x、jquery、mysql),ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json...

    jQuery使用ajaxSubmit()提交表单示例

    ajaxSubmit(obj)方法是jQuery的一个插件jquery.form.js里面的方法,所以使用此方法需要先引入这个插件。如下所示: 代码如下:[removed][removed][removed][removed] 那么,如何通过ajaxSubmit(obj)提交数据呢?首先...

    Jquery ajax请求导出Excel表格的实现代码

    直接贴代码吧 $(#btn-export).click(function(){ var exportExcel = export_excel; dataParams[exportExcel] = 1;...').appendTo('body').submit().remove(); delete dataParams[exportExcel];

    解决jquery submit()提交表单提示:f[s] is not a function

    jquery submit()无法提交表单 报错:f[s] is not a function,很是疑惑搜集整理了一些解决方法,感兴趣的朋友可以了解下啊,希望本文对你有所帮助

    jquery-ajax-validation

    jQuery AJAX表单验证 预期数据格式 { " success " : false , " errors " : { " email " : [ " Email is not valid " ], " password " : [ " Password is not valid " , " Password is too short " ] } } 选项 ...

    ajaxform:简单的ajax提交表单插件

    ajaxform 一个简单的ajax提交插件#### ajaxSubmit(options,callback) 通过Jquery AJAX提交表单。 网址,方法,数据等。来自表格的参数。 // bind submit to form$ ( 'form' ) . on ( 'submit' , function ( e ) {...

    浅谈jquery.form.js的ajaxSubmit和ajaxForm的使用

    • 依赖的脚本文件 [removed][removed] [removed][removed] • ajaxSubmit 和ajaxForm区别...在document的ready函数中,使用ajaxForm来为AJAX提交表单进行准备。提交动作必须由submit开始 ajaxForm()适用于以表单提交

Global site tag (gtag.js) - Google Analytics