javascript调用提交回发

javascript调用提交回发

问题描述:

I've read a lot of googling forums, but my simple sample still doesn't work. That is why I ask you to help me with my prob. I have page1 and page 2. I also have for debugging button (submit) in page1 and page2 with function header($direct). This part works and I have full understanding. But I cann't call full postback via javascript function. I don't know where is my fault. This is my union code for page1:

<?php
if (isset($_POST['btn']))
{
   header('Location: page2.php');
}
elseif (isset ($_POST['btn2']))
{
   header('Location: page2.php');
}
?>

<h1>This is page 1</h1>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
   <input type="submit" name="btn" value="submit: goto page2"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" name="btn2" id ="btn2" value="button: goto page2" onclick="postback();" />
</form>

<script type="text/javascript">
   function postback(){
 var f = document.getElementById('form1');
f.submit();
   }
</script>



I want to call full postback without ajax because with ajax I have no problems. In last example I tried to call javascript postback with selection object and I couldn't any problems with it. But now, when I try to use simple button onclick event it still doesn't work. why? I hope you understand my English and point me to my faults. Thank you in advance

我已经阅读了很多谷歌搜索论坛,但我的简单样本仍然不起作用。 这就是为什么我请你帮我解决问题。 我有第1页和第2页。我还有第1页和第2页的调试按钮(提交)和函数标题($ direct)。 这部分有效,我对此有充分的了解。 但我不能通过javascript函数调用完整的回发。 我不知道我的错在哪里。 这是我的第1页的联合代码:
p>

 &lt;?php 
if(isset($ _ POST ['btn']))
 {
 header(  'location:page2.php'); 
} 
elseif(isset($ _POST ['btn2']))
 {
 header('Location:page2.php'); 
} 
?&gt;  
 
&lt; h1&gt;这是第1页&lt; / h1&gt; 
&lt; form id =“form1”name =“form1”method =“post”action =“&lt;?php $ _SERVER ['PHP_SELF']?&gt  ;“&gt; 
&lt; input type =”submit“name =”btn“value =”submit:goto page2“/&gt;&amp; nbsp;&amp; nbsp;&amp; nbsp;&amp; nbsp;&amp; nbsp;  
&lt; input type =“button”name =“btn2”id =“btn2”value =“button:goto page2”onclick =“postback();”  /&gt; 
&lt; / form&gt; 
 
&lt; script type =“text / javascript”&gt; 
 function postback(){
 var f = document.getElementById('form1'); 
f.submit(  ); 
} 
&lt; / script&gt; 
  code>  pre> 
 
 



我想在没有ajax的情况下调用完整回发,因为使用ajax我没有问题 。 在最后一个例子中,我尝试用选择对象调用javascript postback,我不会遇到任何问题。 但现在,当我尝试使用简单的按钮onclick事件时,它仍然无法正常工作。 为什么? 我希望你理解我的英语并指出我的错误。 提前谢谢 p> div>

input type button will not show value in post

if you want to pass anything into post try input type=hidden

try this

<input type="submit" name="btn2" id ="btn2" value="button: goto page2" onclick="postback();" />

make type as submit it worked for me

The problem is in your statement. Your action statement is: php $_SERVER['PHP_SELF'] ... You need to put echo in there so PHP knows to echo the variable: echo $_SERVER['PHP_SELF']

It's always the little things.