0
我一直试图去函数后面的代码,以获得两个变量加密以返回查询字符串。但我一直没有成功。第一次尝试Ajax。从Ajax函数调用代码背后的c#函数
所以,在后面的代码我有这样的方法:
[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() { }
})
}
试图阿贾克斯之前,它会工作,内部消除尝试去后面的代码。我有这样的:
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的建议格式化了它,并且它工作正常。
RequestObject对象在哪里?事情是,我想要这两个,这是一个名称和一封电子邮件传递给C#方法进行加密,然后返回它们。所以,我不完全有一个对象可以通过。 – taiko
编辑我的响应以包含RequestObject类。你可以任何你想要的名称命名你的两个属性,只要确保在C#类和javascript对象中命名它们相同即可。 –
我似乎无法得到它的工作。我知道它到达了Ajax函数。我在那儿放了一个警报器,它就到了那里。但似乎只是停在那里。它似乎没有进入$ .ajax函数... :( – taiko