【发布时间】:2015-04-12 10:57:55
【问题描述】:
我有这个我正在使用的 Salesforce“Web-to-Lead”表单(在 IIS 服务器上),并且我在 Ajax 调用中正确验证了它(使用 roscripts.com ajax 验证作为起点...这使用 Mootools 库来执行其 Ajax 功能),以及使用 cURL 发送所有经过验证的数据,但是我希望表单在验证成功后重定向到新页面。每次单击“提交”按钮时都会运行 Ajax 调用,并且要么在页面上显示错误,要么运行验证代码的“else”部分中包含的任何内容。
Ajax 函数:
window.addEvent('domready', function() {
$('registerForm').addEvent('submit', function(e) {
new Event(e).stop();
var log = $('log_res').empty().addClass('ajax-loading');
this.send({
update: log,
onComplete: function() {
log.removeClass('ajax-loading');
//adding a header redirect here works, but redirects every time ajax call runs, regardless if validation succeeds or not
}
});
});
});
“动作”php文件函数:
<?php
if (rule){ //validation errors }
else { //where all of the logic happens after validation succeeds
//cURL function
//redirect attempts:
header( 'Location: http://www.place.com'); // doesn 't work
echo '<meta http-equiv="refresh" content="2" ; url="http://www.place.com">'; //resets the form, but doesn't redirect to www.place.com
};
?>
我在这里完全被难住了,无论我多么努力,我都无法重定向这个该死的东西。任何帮助将不胜感激!
【问题讨论】:
-
两种情况下的回报是多少?只需在 oncomplete 中添加一个结果即可知道验证是否成功,如果成功,则重定向。
-
Ajax 调用的文件中的重定向只是在服务器端重定向,并将第二个文件的输出返回给您的 javascript 回调。它不会重定向用户正在查看的页面。
标签: javascript php ajax redirect iis