我有一个Ajax调用服务器,只有当我通过alert();
它的作品。无法弄清楚什么是错的。谁能帮忙?非常奇怪的jQuery/AJAX行为
目的
- 如果 “更新” 按钮,在PrettyPhoto的iFrame点击 - 然后(一)呼叫服务器来运行PHP脚本,更新后端数据库,(二)密切PrettyPhoto窗口,以及(c)刷新 页
- 如果“不更新”按钮,在PrettyPhoto的iFrame点击 - 只是(一)密切PrettyPhoto窗口,和(b)刷新页面
这不工作(即Ajax调用服务器不取得):
jQuery.support.cors = true; // needed for ajax to work in certain older browsers and versions
$('input[name="status"]').on("change", function() {
if ($('input:radio[name="status"]:checked').val() == 'Y') {
$.ajax({
url: 'http://mydomain.com/dir/myPHPscript.php?param=' + $('#param').val() + '&id=' + ($('#id').val() * 1) + '&mode=' + $('#mode').val()
});
}
window.parent.closePP();
window.top.location.href = $('#redirect').val(); // reloads page
});
This Works! (即,当我有警报()目前Ajax调用服务器被提出。):
jQuery.support.cors = true; // needed for ajax to work in certain older browsers and versions
$('input[name="status"]').on("change", function() {
if ($('input:radio[name="status"]:checked').val() == 'Y') {
$.ajax({
url: 'http://mydomain.com/dir/myPHPscript.php?param=' + $('#param').val() + '&id=' + ($('#id').val() * 1) + '&mode=' + $('#mode').val()
});
alert('this makes it work');
}
window.parent.closePP();
window.top.location.href = $('#redirect').val(); // reloads page
});
感谢。
根据答案做了很多修改 - 仍然无法使其工作。下面是最新的:
jQuery.support.cors = true; // needed for ajax to work in certain older browsers and versions
$('input[name="status"]').on("change", function() {
if ($('input:radio[name="status"]:checked').val() == 'Y') {
$.ajax({
url: 'http://mydomain.com/dir/myPHPscript.php?param=' + $('#param').val() + '&id=' + ($('#id').val() * 1) + '&mode=' + $('#mode').val(),
success: functions(data) {var $doNothing = data;}
});
}
window.parent.closePP();
window.top.location.href = $('#redirect').val(); // reloads page
});
最晚将无法正常工作。您必须将关闭位置更改为成功 – mplungjan 2012-04-07 20:32:25
(@mplungjan),并且它不关闭也不重定向。但后端数据库通过ajax调用得到更新... – 2012-04-07 20:39:54