简体   繁体   English

表单操作网址与页面网址不同

[英]Form action URL is different than page URL

Issue : I have a form that has a different form action="url" than the page URL the form resides in. 问题 :我有一个表单,该表单的表单action =“ url”与表单所驻留的页面URL不同。

page URL = www.page.com 网页网址= www.page.com
form action = " http://www.differentserver.com " 表单操作=“ http://www.differentserver.com

Problem : When posting the form it navigates to the form action URL. 问题 :发布表单时,它导航到表单操作URL。

Question : What is the best way to still POST to the action URL but stay on the Form page using jquery/ajax 问题 :仍然是POST到操作URL但仍使用jquery / ajax保留在“表单”页面上的最佳方法是什么

Also, the action URL post back an xml stating if the lead went through. 另外,操作网址会发回一个xml,指出线索是否通过。

You cannot use AJAX to submit data to another domain. 您不能使用AJAX将数据提交到另一个域。

However you can use an old "hack": 但是,您可以使用旧的“ hack”:

<form action="http://www.differentserver.com/" method="post" target="hiddeniframe">
    ...
</form>
<iframe style="display:none" name="hiddeniframe"></iframe>

This will submit the form to the other domain, but won't appear to affect the current document. 这会将表单提交到其他域,但似乎不会影响当前文档。

您始终可以将其发布到隐藏的Iframe target='framename'并挂接到Iframe的ONLOAD事件中以检测其完成时间。

在differentserver.com之后重定向,或使用curl执行操作

Jquery does this well jQuery做得很好

Posting the entire form 过帐整个表格

//Jquery Code
$.post("test.php", $("#form_name").serialize(), function(result){
 // return 
 var aa = result;

});

Posting specific parts of the form 发布表单的特定部分

//Jquery Code
 /* get some values from elements on the page: */
 var $form = $( this ),
  term = $form.find( 'input[name="s"]' ).val(),
  url = $form.attr( 'action' );

 /* Send the data using post */
 var posting = $.post( url, { s: term } );

 /* Put the results in a div */
 posting.done(function( data ) {
   var content = $( data ).find( '#content' );
  $( "#result" ).empty().append( content );
   });

If you are using a Submit button, this will stop the form from posting normally. 如果您使用的是“提交”按钮,这将阻止表单正常发布。

 /* stop form from submitting normally */
  event.preventDefault();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM