问题描述
我使用页面方法来检索登录信息。我的代码如下,
$ .ajax({
type:POST,
url :Main.url + loginBox.url,
data:'{jsonrpc:2.0,method:login,params:{login:''+ nameVal +', pass:'+ passVal +'''+(loginBox.userSaveUdid?,id:1}',
async:true,
dataType:json,
contentType: application / json,
beforeSend:function(){
alert(--------------------------- -------------------------------------------------- -------- loginBox.submit:beforeSend);
$(#login-error)。html();
Loading.show();
},
成功:函数(数据){
alert(---------------------------- -------------------------------------------------- ------- loginBox.submit:success =);
if(data.error){
$(#login-error)。html (data.error.message)
} else {
loginBox.LogInSuccess(nameVal,data.result.user_id,data.result.token)
/ *
loginBox.userName = nameVal;
loginBox.userLogged = data.result.user_id;
loginBox.userToken = data.result.token;
Limit.getLimit();
loginBox.hide();
* /
}
},
complete:function(){
alert(-------- -------------------------------------------------- --------------------------- loginBox.submit:complete);
Loading.hide();
},
error:function(XMLHttpRequest,textStatus,errorThrown){
$(#login-error)。html(textStatus)
alert(---- -------------------------------------------------- ------------------------------- loginBox.submit:error+ textStatus);
}
});
我得到404未找到页面错误。我用萤火虫来检查这些和请求和响应。
这就是我得到的。 b
$ b
通过1.1 BILEETAISA
连接Keep-Alive
代理连接Keep-Alive
内容长度728
日期2011年7月27日星期三22:17:53 GMT
Content-Type text / html; charset = UTF-8
服务器Apache / 2.2.3(CentOS)
X-Powered-By Phusion Passenger(mod_rails / mod_rack)3.0.7
X-Runtime 0.004490
状态404
请求Headersview
Host xxxx.tv
User-Agent Mozilla /5.0(Windows NT 5.1; rv:5.0.1)Gecko / 20100101 Firefox / 5.0.1
接受text / html,application / xhtml + xml,application / xml ; q = 0.9, / ; q = 0.8
Accept-Language en-us,en; q = 0.5
$ b
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8; q = 0.7,*; q = 0.7
代理连接保持活动状态
来源空白
访问控制请求我... POST
访问控制请求 - 他...内容类型
Pragma no-cache
Cache-Control no-cache
Can有人告诉我错在哪里。它应该是接受应用程序/ json请求头中的字段吗?我是否应该将json库添加到我的项目中?仅仅使用jQuery是不够的。如果这是愚蠢的问题,请原谅我。
检查您的网址是否正确
url:Main.url + loginBox.url
首先复制您的正确网页网址和方法名称。请检查。
例如
var pageUrl =' Contact.aspx;
$ .ajax({
url:pageUrl +'/ SendMail',
type:POST,
data:'{Name:''+ Name +', FromEmail:'+ FromEmail +',Body:'+ Body +'}',
dataType:json,
contentType:application / json,
成功:函数(data){
if(data.d == 1){
$(input [type = button])。val(Send Mail);
alert( ('''''');
$('#fade') );
}
}
});
I'm using page method to retrieve login information. My code goes as follows,
$.ajax( {
type: "POST",
url: Main.url + loginBox.url ,
data: '{"jsonrpc": "2.0", "method": "login", "params": {"login": "'+nameVal+'", "pass": "'+passVal+'"'+ ( loginBox.userSaveUdid ? ","id": 1}',
async: true,
dataType: "json",
contentType: "application/json",
beforeSend: function(){
alert("-------------------------------------------------------------------------------------loginBox.submit : beforeSend");
$("#login-error").html();
Loading.show();
},
success: function(data) {
alert("-------------------------------------------------------------------------------------loginBox.submit : success = ");
if( data.error ){
$("#login-error").html(data.error.message)
}else{
loginBox.LogInSuccess(nameVal,data.result.user_id,data.result.token)
/*
loginBox.userName = nameVal;
loginBox.userLogged = data.result.user_id;
loginBox.userToken = data.result.token;
Limit.getLimit();
loginBox.hide();
*/
}
},
complete: function(){
alert("-------------------------------------------------------------------------------------loginBox.submit : complete");
Loading.hide();
},
error: function(XMLHttpRequest, textStatus, errorThrown){
$("#login-error").html(textStatus)
alert("-------------------------------------------------------------------------------------loginBox.submit : error " +textStatus);
}
});
I'm getting 404 Not page found error. I used firebug to check those and request and responses.
this what i got.
Via 1.1 BILEETAISA
Connection Keep-Alive
Proxy-Connection Keep-Alive
Content-Length 728
Date Wed, 27 Jul 2011 22:17:53 GMT
Content-Type text/html; charset=UTF-8
Server Apache/2.2.3 (CentOS)
X-Powered-By Phusion Passenger (mod_rails/mod_rack) 3.0.7
X-Runtime 0.004490
Status 404
Request Headersview
Host xxxx.tv
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1
Accept text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Proxy-Connection keep-alive
Origin null
Access-Control-Request-Me... POST
Access-Control-Request-He... content-type
Pragma no-cache
Cache-Control no-cache
Can someone tell me where is the fault. Is it should be accept field in request header as application/json? Should i add to json library to my project also? Isn't that enough with only jquery. Pardon me if this is dumb question. I'm newer to this stuffs.
Check your URL for correct
url: Main.url + loginBox.url
First copy past your correct page URL and method name . then check please .
For sample is
var pageUrl = 'Contact.aspx';
$.ajax({
url: pageUrl + '/SendMail',
type: "POST",
data: '{Name: "' + Name + '",FromEmail: "' + FromEmail + '",Body: "' + Body + '"}',
dataType: "json",
contentType: "application/json",
success: function (data) {
if (data.d == 1) {
$("input[type=button]").val("Send Mail");
alert("Mail successfully sent");
$('#envelope').css('display', 'none');
$('#fade').css('display', 'none');
}
}
});
这篇关于jquery ajax pagemethod无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!