我正在使用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
发布评论