我一直在尝试使用函数后面的代码来获取两个加密的变量作为查询字符串返回。但我没有成功。第一次尝试Ajax。
所以,在代码背后我有这个方法:
[WebMethod]
public static string EncritaDados(string str, string str2)
{
return Verificacoes.EncryptString(str)+";"+ Verificacoes.EncryptString(str2);
}
在我的ASP中,我有这个(实现facebook登录):
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me?fields=name,email', function (response) {
console.log('Successful login for: ' + response.name);
Ajax(response.email, response.name)
});
}
function Ajax(expressao1, expressao2) {
$.ajax({
url: 'login.aspx/EncritaDados',
method: 'post',
contentType:'application/json',
data: '{str: ' + expressao1 + ', str2: ' + expressao2 + '}',
dataType:'json',
success: function (resp) {
var strings = resp.d.split(";");
window.location.href = 'login.aspx?email=' + strings[0] + '&nome=' + strings[1];
},
error: function () { }
})
}
在尝试Ajax之前,它会工作,而不是试图找到后面的代码。我有这样的话:
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me?fields=name,email', function (response) {
console.log('Successful login for: ' + response.name);
window.location.href = 'login.aspx?email=' + response.email+ '&nome=' + response.name;
});
}
我现在正在挠头。谁能帮我这个?我很感激。
编辑:我这样得到了:function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me?fields=name,email', function (response) {
console.log('Successful login for: ' + response.name);
Ajax(response.email, response.name);
});
}
function Ajax(expressao1, expressao2) {
var request = { email: expressao1, nome: expressao2 }
$.ajax({
url: 'login.aspx/EncritaDados',
method: 'post',
contentType: 'application/json',
data: JSON.stringify(request),
dataType: 'json',
success: function (resp) {
var strings = resp.d.split(";");
window.location.href = 'login.aspx?email=' + strings[0] + '&nome=' + strings[1];
},
error: function (error) { alert(error.status); }
})
在代码背后:
[WebMethod]
public static string EncritaDados(string email, string nome)
{
return Verificacoes.EncryptString(email) + ";" + Verificacoes.EncryptString(nome);
}
所以,基本上,我做了一些小改动,但它没有做到它应该做的事情,因为数据字符串形成不好。但是我按照JSON.stringify的建议对其进行了格式化,并且它有效。
答案 0 :(得分:1)
您的javascript中有错误。 resp.d而不是resp.data:
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me?fields=name,email', function (response) {
console.log('Successful login for: ' + response.name);
Ajax(response.email, response.name)
});
}
function Ajax(expressao1, expressao2) {
var requestObject = { str : expressao1, str2 : expressao2 }
$.ajax({
url: 'login.aspx/EncritaDados',
method: 'post',
contentType:'application/json',
data: JSON.stringify(requestObject),
dataType:'json',
success: function (resp) {
var strings = resp.data.split(";");
window.location.href = 'login.aspx?email=' + strings[0] + '&nome=' + strings[1];
},
error: function () { }
})
}