JQuery ajax()方法
我的ajax方法总是返回ServiceFailed,尽管WCF服务方法返回成功(我通过设置断点进行了验证)。代码如下所示。怎么了JQuery ajax()方法,jquery,Jquery,我的ajax方法总是返回ServiceFailed,尽管WCF服务方法返回成功(我通过设置断点进行了验证)。代码如下所示。怎么了 function LoginToServer(name, password) { server = "localhost:1706"; Type = "GET"; var encodeusername = $.base64.encode(encode_utf8(name.value)); var encodepwd = encode_u
function LoginToServer(name, password) {
server = "localhost:1706";
Type = "GET";
var encodeusername = $.base64.encode(encode_utf8(name.value));
var encodepwd = encode_utf8(password.value);
var params = 'username=' + encodeusername + '&password=' + encodepwd + '&clientip=none';
Url = "http://" + server + "/WCF/Test/TestService.svc/rest/Login?" + params;
ContentType = "application/json; charset=utf-8";
DataType = "jsonp";
ProcessData = true;
JsonpCallback = "alertResponse",
method = "Login";
CallService();
}
function CallService() {
$.ajax({
type: Type, //GET or POST or PUT or DELETE verb
url: Url, // Location of the service
data: Data, //Data sent to server
contentType: ContentType, // content type sent to server
dataType: DataType, //Expected data format from server
processdata: ProcessData, //True or False
jsonpCallback: JsonpCallback,
success: function (msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
WCF服务方式定义如下:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json,
UriTemplate = "/Login?username={username}&password={password}&clientip={clientip}")]
AuthenticationStatus SlideViewerLogin(string username, string password, string clientip);
谢谢。有关跨域呼叫,请检查此项 用于WCF呼叫 WCF服务可能存在一些问题,也请查看这篇帮助您找出所面临错误的博文: 尝试以json格式传递数据,如下所示
var msg2 = { "UserName": "Denny", "Password": "abc123" };
Data = JSON.stringify(msg2);
我认为您需要在有数据的地方传递变量“params”:data,。它正在数据中查找某些内容,但我在函数中没有看到名为data的变量。能否检查从Web服务返回的数据类型是否与预期的数据类型(jsonp)匹配?我如何检查?请让我知道。您好……请查看我回答中的博客帖子,这将解决您的问题……您可以粘贴服务器端代码吗?@bygrace:请查看上面修改的帖子。当我尝试这种方法时,我总是会发现下面的错误。”加载资源失败:服务器响应状态为400(错误请求)“@codematrix-从此处下载代码,然后重试