如果页面被刷新,如何运行ajax脚本
How to run ajax script if the page is refreshed
我希望ajax脚本在页面刷新时执行。
我的问题是它不工作- ajax脚本没有运行。
脚本:
$(window).bind("load", function() {
var data = {};
data.emailCodeResult = $('#emailCodeResult').val();
$.ajax({
type: "POST",
url: "Oppa/view/viewOther.php",
data: data,
cache: false,
dataType:"JSON",
success: function (result) {
$("#prof_talent").val(result.oth_hobbies);
$("#prof_recognition").val(result.oth_recognition);
$("#prof_organization").val(result.oth_organization);
$("#prof_workExperience").val(result.oth_workExperience);
$("#prof_trainingPrograms").val(result.oth_trainingPrograms);
$(".show-page[data-page=Profile_Other_info]").trigger("click");
}
});
return false;
});
从您的评论中听起来,当您的AJAX调用触发时,$('#emailCodeResult').val()
仍然为空。既然你使用setinterval
不断地重新填充它,为什么不在AJAX调用之前放一个do/while循环,以确保data.emailCodeResult
得到内容?
//helper function (see http://www.sitepoint.com/delay-sleep-pause-wait/)
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
do{
sleep(2000);
}
while($('#emailCodeResult').val() == 'undefined');
//AJAX call here
相关文章:
- 如何在加载网页时运行脚本
- 使用JavaScript运行脚本
- javascript动态内容与选择长运行脚本
- Javascript:在新页面中打开链接并运行脚本
- 如何在内部脚本完全加载后运行脚本
- 对couchdb数据库/视图中的所有文档运行脚本/查询
- 单击1个表单中的2个提交按钮中的1个时,如何运行脚本
- 是否可以在node.js依赖项上运行脚本
- "npm运行构建:css"不能工作,而当我自己运行脚本时是可以的
- 运行脚本以禁用脚本
- 在网络whatsapp上运行脚本
- 仅在 url 索引上运行脚本
- [XSS]Expressjs 阻止从 POST 请求运行脚本
- 在触发无限滚动时运行脚本
- 使用Browserify运行脚本,无需先进行构建过程
- "停止运行脚本错误“;在IE8中拥有大量收藏
- PHP-如何让别人可以'不要更改url中的参数,也不要在刷新页面时再次运行脚本
- 如何在不阻塞脚本的情况下运行脚本
- 如果用户登录不起作用,则运行脚本
- 我想在用Jquery.ajax方法加载数据后在Html中运行脚本