【发布时间】:2014-12-08 16:36:58
【问题描述】:
在测试这段代码时,我特意让它从 ajax 调用返回的文本不是 1。它到达了 else 语句。其他语句执行,但是,我从来没有看到警报。
$.ajax ( {
type: "GET",
processData: false,
url: SITE_URL + "/system/check_user_project/" + session_id + "/" + cart_id + "/" + project_id + "/" + revision_id, //send data to this url
dataType: 'text',
})
.done (function(text) //When we have the data
{
if ("1" == text)
{
photos_populate_albums(session_id); //Call function to populate albums
if (typeof(project_id) !== "undefined" && project_id > 0) //If we have a project
{
mattes_add_default_matte(null, null, null, null, SITE_URL + "/system/xml/export/" + project_id + "?rid=" + revision_id);
}
else //otherwise...
{
mattes_add_default_matte(); //Add the default matte
}
common_change_step(document.getElementById("step1")); //Set the step to 1
}
else
{
$("#content").empty();
alert("Invalid project.");
window.location.href = (SITE_URL + "/user/mystuff/projects/?pid=" + partner_id);
}
});
更新:我刚刚意识到我不小心选中了询问您是否要在此网页出现时继续接收来自该网页的警报的框。现在我不知道在哪里撤消它。
【问题讨论】:
-
浏览器控制台有错误吗?
-
你怎么知道它到达了 else 语句?
-
提示:我会添加
.fail()处理程序只是为了确保它正确执行AJAX调用。 -
您没有勾选“不向我显示此站点的警报”或类似的内容吗?如果你在服务器上测试这个,你确定代码已经正确上传了吗?
-
提示 #2:此处多余的逗号可能会破坏您在
IE:dataType: 'text',上的代码
标签: javascript jquery google-chrome