将表单数据发送到外部url时遇到问题。我知道我需要构建一个php桥来实现这一点,但这就是我的落脚点。
表单标记:
<div class='done' style='background:#fffee1;border:1px solid #fdf96c;padding:10px;'>
Success! We'll be in touch soon
</div>
<div class='form'>
<form method='post' action='http://example.com/external-url'>
<input type="hidden" name="idstamp" id="idstamp" value="would need to pass this too" />
<p class='element'>
<label for='account'>Client Name</label>
<input type='text' id='account' name='account' class='text' />
</p>
<p class='element stack'>
<label for='user'>User Name</label>
<input type='text' id='user' name='user' class='text' />
</p>
<p class='element stack'>
<input type='submit' class='button orange' value='Submit' style='padding:0; width:130px;height:30px' id='submit'/>
<div class='loading'></div>
</p>
</form>
</div>这是一个基本的操作,只需显示一个成功的div,然后隐藏整个表单div:
$('.form').fadeOut('slow');
//show the success message
$('.done').fadeIn('slow');
$('.toggle').delay(5000).fadeOut('slow');缺少的部分是发送到本地.php文件,解析出数据,然后发送到外部url。我到处都在找这个,似乎找不到一个简单的解决方案,希望能在这里找到一个。
发布于 2012-01-11 00:24:13
下面是jquery部分:
$(function(){
...
$(".form form").submit(function(e){
e.preventDefault();
var formData = $(this).serialize();
$.post("bridge.php",formData).done(function(rdata){
if (window.console && window.console.log) {
console.log(rdata);
}
}).fail(function(){
if (window.console && window.console.log) {
console.log(arguments);
}
});
});
...
});现在,您只需要构建接受POST变量并将它们发送到外部url的bridge.php。
https://stackoverflow.com/questions/8806261
复制相似问题