錯誤:Microsoft JScript運行時錯誤:JQuery的Json的錯誤:對象不支持此屬性或方法
:對象不支持此屬性或方法這裏是怎麼json2從主叫
**var json = JSON2.stringify(settings.data);**
我使用WCF服務來拉動數據和它的測試的目的很簡單,它並返回我從WCF服務的數據,但對行號json2.js失敗314-316
// 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,但是我得到上面的同樣的錯誤。
嗯,我剛剛更新了整個代碼,以前我只是複製的代碼的一部分這就是爲什麼你發現了缺少右括號。 – 2010-05-01 04:36:38