Javascript 错误:对象不存在';t支持属性或方法';指数';

Javascript 错误:对象不存在';t支持属性或方法';指数';,javascript,asp.net-mvc-3,jquery,Javascript,Asp.net Mvc 3,Jquery,我有一个对JsonAction的ajax调用 $.ajax({ url: "/Cancel/", context: document.body, success: function (result) { if (result.indexOf("Authorize") != -1) //indexOf not supported?

我有一个对JsonAction的ajax调用

              $.ajax({
                url: "/Cancel/",
                context: document.body,
                success: function (result) {
                    if (result.indexOf("Authorize") != -1) //indexOf not supported?
                              window.location.replace("/Account/LogOn");
                         //...
              };
为什么会这样

我也试着这样做:

var responce = result;
if (responce.indexOf("Authorize") != -1)


但还是一样。Ned帮助如何使.indexOf工作。

服务器响应可能被解释为JSON,并由jQuery自动转换为数据对象。在这种情况下,它可能不会有
indexOf
成员,当然也不会是函数

通过将设置对象的
dataType
属性设置为“text”,尝试强制jQuery将响应保留为文本:


您好,请尝试使用这种方式

$.ajax({
            url: "/Cancel/",
            context: document.body,
            success: function (result) {
              var str=String(result);
                if (str.indexOf("Authorize") != -1) //indexOf not supported?
                          window.location.replace("/Account/LogOn");
                     //...
                     //...
          };

您的ajax调用返回什么?将一个
警报(结果)
作为成功处理程序的第一行,并查看实际结果。
$.ajax({
  url: "/Cancel/",
  dataType: "text",
  ...
$.ajax({
            url: "/Cancel/",
            context: document.body,
            success: function (result) {
              var str=String(result);
                if (str.indexOf("Authorize") != -1) //indexOf not supported?
                          window.location.replace("/Account/LogOn");
                     //...
                     //...
          };