jQuery的/ ASP MVC - parsererror在" $ AJAX"电话 [英] jQuery / ASP MVC -- parsererror in "$.ajax" calls

查看:113
本文介绍了jQuery的/ ASP MVC - parsererror在" $ AJAX"电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建使用jQuery 1.3.1在ASP.Net MVC RC2一个简单的动作链接 - 是这样的:

I'd like to create a simple action link in ASP.Net MVC RC2 using jQuery 1.3.1 - something like this:

< A HREF =#的onclick =AjaxTest1()>测试< / A>

AjaxTest1 功能:


function AjaxTest1() {
            $.ajax({
                    url: "Home/Ajax1",
                    error: function(request, status, error) {
                        alert("error: " + status + ", " + "\n" +
                               error + ", " + request.responseText +
                               request.getAllResponseHeaders());
                    },
                    success: function(data, status) {
                         alert("Finally, it worked!");
                    },
                    type: "GET",
                    dataType: "text",
                });
                return false;
        }

和控制器动作:


public ActionResult Ajax1()
        {
            return this.Content("Test Content");
        }

所有我想要做的是返回一个简单的字符串 - 但错误回调总是调用 parseerror 的错误。该XmlHtt prequest中有内容的字符串考试内容 - 这样的控制器动作被调用,并返回正确的数据。我试图设置的数据类型(以文,HTML,JSON),使用JsonResult类型的控制器,设置返回的内容类型为text / plain的,使用$不用彷徨,$ .getJson,等...没有什么作品。我觉得我必须失去了一些非常,非常简单的 - 尤其是因为谷歌是没有帮助。想法?

All I'm trying to do is return a simple string - but the "error" callback is always called with an error of parseerror. The XmlHttpRequest has the content string "Test Content" in it - so the controller action is being called and the correct data is being returned. I've tried to set the dataType (to "text", "html", "json"), to use the JsonResult type in the controller, to set the returned content type to "text/plain", to use $.get, $.getJson, etc... nothing works. I feel like I must be missing something very, very simple - especially since google is no help. Ideas?

推荐答案

我无法相信我想通了这一点 - 没有在的jQuery 1.3.1错字* vsdoc.js (它在和jQuery.httpData 如果有任何人有兴趣 - 他们定义的输入参数为过滤器,然后尝试引用它作为取值,它抛出一个异常)。奇怪的是,如果使用非* vsdoc版本,错字是不存在的。

I can't believe I figured this out - there is a typo in the jquery-1.3.1*vsdoc.js (its in jQuery.httpData if anyone out there is interested - they define the input parameter as filter, then try to reference it as s, which throws an exception). Oddly, if you use the non *vsdoc version, the typo isn't there.

看起来他们发布的jQuery 1.3.2与vsdocs - 它没有错字。所以,我想说的答案是只下载更新。 ( jQuery的下载页面

Looks like they released jQuery-1.3.2 with vsdocs - which doesn't have the typo. So I'd say the answer is to just download the update. (jQuery Download Page)

里去了我生命中的一天...希望这可以帮助别人。

There went a day of my life... hope this helps someone.

这篇关于jQuery的/ ASP MVC - parsererror在" $ AJAX"电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆