我正在开发SilverLight应用程序,其中在浏览器关闭事件中,我需要执行Web服务调用。我有一个接受一个参数的Web服务方法。当用户点击浏览器关闭事件时。我将会调用doRelease()函数。 releaseuser方法需要一个参数usertoken。JQuery:调用Web服务
我在调用我的jQuery函数CallService()时出错。
Line: 186 Error: Object expected
var varType;
var varUrl;
var varData;
var varContentType;
var varDataType;
var varProcessData;
//Generic function to call AXMX/WCF Service
function CallService() {
$.ajax({
type: varType, //GET or POST or PUT or DELETE verb
url: varUrl, // Location of the service
data: varData, //Data sent to server
contentType: varContentType, // content type sent to server
dataType: varDataType, //Expected data format from server
processdata: varProcessData, //True or False
success: function (msg) {//On Successfull service call
alert("success");
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
function Temp(usertoken) {
varType = "POST";
varUrl = "http://localhost/TempWS/MachineHistoryWS.asmx?op=ReleaseUser";
varData = usertoken;
varContentType = "application/json; charset=utf-8";
varDataType = "json";
varProcessData = true;
alert("call service");
CallService();
}
function ServiceSucceeded(result) {//When service call is sucessful
alert("success");
varType = null; varUrl = null; varData = null; varContentType = null; varDataType = null; varProcessData = null;
}
function ServiceFailed(result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
varType = null; varUrl = null; varData = null; varContentType = null; varDataType = null; varProcessData = null;
}
function doRelease() {
var usertoken = readCookie("usertoken");
Temp("usertoken");
}
由于在你的例子中少于50行,你可以给我们所有的提示什么代码是在你的实际页面186行吗? :) – 2010-08-25 11:11:22
它在进入函数CallService()时发生。你可以说发送我的参数?这是对的吗? – xscape 2010-08-25 11:25:55
这与Silverlight有什么关系? – Pointy 2010-08-25 12:38:25