ASP.NET MVC3和jquery表单插件(ASP.NET MVC3 and jquery form plugin)

系统教程 行业动态 更新时间:2024-06-14 17:04:02
ASP.NET MVC3和jquery表单插件(ASP.NET MVC3 and jquery form plugin)

我正在使用ASP.NET MCV3,jquery 1.5.2和jquery表单插件。 这是示例代码:

<script type="text/javascript"> // wait for the DOM to be loaded $(document).ready(function () { $('#uploadForm').ajaxForm({ dataType: 'json', beforeSubmit: function () { alert('beforeSubmit'); }, success: function() { alert('success'); }, error: function () { alert('error'); } }); }); </script> <form id="uploadForm" action="@Url.Action("UploadFile")" method="post"> <input type="submit" value="Submit file" /> </form> [AcceptVerbs(HttpVerbs.Post)] public JsonResult UploadFile() { return Json(new { message = "success" }); }

当我提交表单时,我总是收到以下错误消息: 预期';' 我搜索了SO,Google ..但找不到任何解决方案。

我在这里找到了Darin的评论,但我需要在提交和成功事件之前。

任何帮助将不胜感激!

I'm using ASP.NET MCV3, jquery 1.5.2 and jquery form plugin. Here's the sample code:

<script type="text/javascript"> // wait for the DOM to be loaded $(document).ready(function () { $('#uploadForm').ajaxForm({ dataType: 'json', beforeSubmit: function () { alert('beforeSubmit'); }, success: function() { alert('success'); }, error: function () { alert('error'); } }); }); </script> <form id="uploadForm" action="@Url.Action("UploadFile")" method="post"> <input type="submit" value="Submit file" /> </form> [AcceptVerbs(HttpVerbs.Post)] public JsonResult UploadFile() { return Json(new { message = "success" }); }

When I submit the form, I always get the following error message: Expected ';' I searched SO, Google.. but couldn't find any solution to this problem.

I found Darin's comment here, but I need to have beforeSubmit and success events.

Any help would be greatly appreciated!

最满意答案

我将dataType从json更改为text,然后我解析了结果。 一切接缝都可以正常工作。

<script type="text/javascript"> // wait for the DOM to be loaded $(document).ready(function () { $('#uploadForm').ajaxForm({ dataType: 'text', beforeSubmit: function () { alert('beforeSubmit'); }, success: processJson, error: function () { alert('error'); } }); }); function processJson(responseJson) { var obj = jQuery.parseJSON(responseJson); alert(obj.message); } </script>

I changed dataType from json to text and then I parsed the result. Everything seams to work ok.

<script type="text/javascript"> // wait for the DOM to be loaded $(document).ready(function () { $('#uploadForm').ajaxForm({ dataType: 'text', beforeSubmit: function () { alert('beforeSubmit'); }, success: processJson, error: function () { alert('error'); } }); }); function processJson(responseJson) { var obj = jQuery.parseJSON(responseJson); alert(obj.message); } </script>

更多推荐

success,type,function,电脑培训,计算机培训,IT培训"/> <meta name="descrip

本文发布于:2023-04-24 20:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/9454234e5c3a75242128746aa5382f1c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   插件   NET   ASP   plugin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!