ASP 使用 Ajax 获取变量的值而不是引用
ASP getting the value of a variable rather than a reference with Ajax
目前我已经在这段代码上停留了将近两天,现在正在查找我能找到的所有内容,但我尝试过的任何东西都没有完全解决,这可能部分是由于我不正确地实现它或其他原因,但我想我最终会问。我应该首先说我在一个花哨的盒子里。我希望 bIsError 的 true 的值显示在 console.log 中,但是 window.alert 告诉我它是设置为假。我确实注意到,一旦我 运行 通过我的代码,该值就会发生变化。例如 - 如果用户名不正确 returns false 然后将 bIsError 设置为 true 并显示一条错误消息。但是我只需要它 return true 然后给出错误,这样我的代码就可以工作了。无论如何,这是我的代码,也感谢任何人的反馈,我真的很感激。
if (typeof bFirstLoginPrep == 'undefined') {
var bFirstLoginPrep = true;
}
if (typeof $ != 'undefined') $(function () {
$(".ajaxformsubmit").unbind("click");
$(".ajaxformsubmit").click(function (event) {
setTimeout("lfSubmitForm()", 100);
return false;
});
});
function lfSubmitForm()
{
$form = $(".ajaxformsubmit").parents("form");
response = $.ajax({
url: $form.attr("action"),
type: "POST",
async: false,
data: $form.serialize()
}).responseText;
var responseList = false;
if (responseList == <%=LCase(bisError)%>) {
lfLoginSuccess();
} else {
$("#fancybox-inner").html(response);
$.fancybox.resize();
}
}
- 恐龙梦
<%=bIsError%> gives you the value of an instance server-side variable. If you are updating it via Ajax, it wouldn't work because you are probably making an ajax call to a pagemethod which is declared as static and static methods cannot manipulate the instance members of the page. In order to make it work with ajax, you need to return bIsError as part of the ajax response.
- 阿摩司
Yes, as DinoMyte says. Also you could set blsError as a session variable in this script before it is sent to the browser and then the script that the ajax calls can read it server-side.
目前我已经在这段代码上停留了将近两天,现在正在查找我能找到的所有内容,但我尝试过的任何东西都没有完全解决,这可能部分是由于我不正确地实现它或其他原因,但我想我最终会问。我应该首先说我在一个花哨的盒子里。我希望 bIsError 的 true 的值显示在 console.log 中,但是 window.alert 告诉我它是设置为假。我确实注意到,一旦我 运行 通过我的代码,该值就会发生变化。例如 - 如果用户名不正确 returns false 然后将 bIsError 设置为 true 并显示一条错误消息。但是我只需要它 return true 然后给出错误,这样我的代码就可以工作了。无论如何,这是我的代码,也感谢任何人的反馈,我真的很感激。
if (typeof bFirstLoginPrep == 'undefined') {
var bFirstLoginPrep = true;
}
if (typeof $ != 'undefined') $(function () {
$(".ajaxformsubmit").unbind("click");
$(".ajaxformsubmit").click(function (event) {
setTimeout("lfSubmitForm()", 100);
return false;
});
});
function lfSubmitForm()
{
$form = $(".ajaxformsubmit").parents("form");
response = $.ajax({
url: $form.attr("action"),
type: "POST",
async: false,
data: $form.serialize()
}).responseText;
var responseList = false;
if (responseList == <%=LCase(bisError)%>) {
lfLoginSuccess();
} else {
$("#fancybox-inner").html(response);
$.fancybox.resize();
}
}
- 恐龙梦
<%=bIsError%> gives you the value of an instance server-side variable. If you are updating it via Ajax, it wouldn't work because you are probably making an ajax call to a pagemethod which is declared as static and static methods cannot manipulate the instance members of the page. In order to make it work with ajax, you need to return bIsError as part of the ajax response.
- 阿摩司
Yes, as DinoMyte says. Also you could set blsError as a session variable in this script before it is sent to the browser and then the script that the ajax calls can read it server-side.