(function ($) {
var serviceUrl;
$.fn.serviceinvoke = function (wstype, method, callback, params) {
// 选择请求服务的类型
switch (wstype) {
case 0:
// 设置为请求WebService
serviceUrl = '/WebService/WebService.asmx/';
break;
case 1:
// 设置为请求WCF
serviceUrl = '/WCFService/WCFService.svc/';
break;
default:
}
$.ajax({
type: "post",
url: serviceUrl + method,
contentType: "application/json;charset=utf-8",
data: params,
dataType: 'json',
timeout: 10000,
success: function (data) {
// 如果是Web Service优先执行
if (data.d) {
callback(data.d);
}
else {
callback(data);
}
},
error: function (XMLHttpRequest, textStatus) {
alert(textStatus);
},
beforeSend: function (xml) {
if (!params)
xml.setRequestHeader("Content-Type", "application/json;utf-8")
},
cache: false
});
};