JQuery Json错误: Object doesn't support this property or method

标签 jquery wcf json

错误:Microsoft JScript 运行时错误:对象不支持此属性或方法

这是 json2 的调用方式:

   **var json = JSON2.stringify(settings.data);**

我正在使用 WCF 服务来提取数据,出于测试目的,它非常简单,它确实从 WCF 服务返回了数据,但在 第 314-316 行的 json2.js 上失败

// We split the first stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace all backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.

                if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

这就是我正在做的事情

    // *** Generic Service Proxy class that can be used to 
// *** call JSON Services generically using jQuery
// *** Depends on JSON2 modified for MS Ajax usage
function serviceProxy(wjOrderServiceURL) {
    var _I = this;
    this.ServiceURL = wjOrderServiceURL;

    // *** Call a wrapped object
    this.invoke = function (options) {

        // Default settings
        var settings = {
            serviceMethod: '',
            data: null,
            callback: null,
            error: null,
            type: "POST",
            processData: false,
            contentType: "application/json", 
            dataType: "text",
            bare: false
        };

        if (options) {
            $.extend(settings, options);
        }

        // *** Convert input data into JSON - REQUIRES Json2.js
        var json = JSON2.stringify(settings.data);

        // *** The service endpoint URL
        var url = _I.ServiceURL + settings.serviceMethod;
      debugger
        $.ajax({
            url: url,
            data: json,
            type: settings.type,
            processData: settings.processData,
            contentType: settings.contentType,
            timeout: settings.timeout,
            error: settings.error,
            dataType: settings.dataType,
            success:
                    function (res) {
                        if (!settings.callback) { return; }

                        // *** Use json library so we can fix up MS AJAX dates
                        var result = JSON2.parse(res);
                        debugger
                        if (result.ExceptionDetail) {
                            OnPageError(result.Message);
                            return;
                        }

                        // *** Bare message IS result
                        if (settings.bare)
                        { settings.callback(result); return; }

                        //http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/
                        if (result.hasOwnProperty('d'))
                        { return settings.callback(result.d); }
                        else
                        { return result; }


                        // *** Wrapped message contains top level object node
                        // *** strip it off
                        //                        for (var property in result) {
                        //                            settings.callback(result[property]);
                        //                            break;
                        //                        }
                    }
        });
    };
}



 function GetFederalHolidays() {

        $("#dContacts1").empty().html('Searching for Active Contacts...');  
        ContactServiceProxy.invoke({ serviceMethod: "Holidays",
            callback: function (response) {
    //           ProcessActiveContacts1(response);
                debugger
            },
            error: function (xhr, errorMsg, thrown) {
                postErrorAndUnBlockUI(xhr, errorMsg, thrown);
            }
        });        
}

wcf 返回我简单的字符串

  public List<string> Holidays()
        {
            List<string> s = new List<string>();
            s.Add("01/01/2010");
            s.Add("02/01/2010");
            s.Add("03/01/2010");
            s.Add("04/01/2010");
            s.Add("05/01/2010");
            return s;

        }

我做错了什么有什么帮助吗?我尝试将 dataType: text 更改为 json 但出现与上面相同的错误。

最佳答案

this.invoke = function (options) {

第一件事是使用匹配的 }; 关闭该函数。

还有一个 } 来关闭第一个函数 serviceProxy

关于JQuery Json错误: Object doesn't support this property or method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2748857/

相关文章:

javascript - jquery如何改变你的网站背景?

jquery - 我怎样才能独特地添加选项来使用jquery进行选择

c# - WCF 客户端使用多个使用 HTTP Cookie 的 asmx 服务

php - file_put_contents 在使用 json_encode 时返回 null

javascript - 为什么我的 json_encode 没有在 PHP 中给出正确的值

jquery - Bootstraps ICheck-Helper 不会在更改事件时触发

jquery - CSS 选择背景图像设置为特定 url 的元素

wcf - 自承载 WCF 数据服务上的 Kerberos 身份验证

c# - 为什么需要 FaultContract,而我们只能使用 FaultException?

javascript - 如何使用 AJAX 和 PHP 迭代将 JSON 数据保存到新的 JSON 文件?