gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 06:08:29 25 4
gpt4 key购买 nike

错误: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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com