在Button元素中,formaction ='**。php'不起作用

时间:2014-02-03 06:23:25

标签: php html ajax

我正在进行Ajax编程。也就是说,First Html开始,第二,php接收html信号,最后显示xml内容。

我制作了html代码和php代码。但是php代码中的按钮形成属性不起作用。 php代码如下所示

   if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q) || stristr($u->item(0)-

    >childNodes->item(0)->nodeValue,$q))
  {
  if ($hint=="")
    {
    $hint="<button type='submit' name='code' value='" . 
    $u->item(0)->childNodes->item(0)->nodeValue . 
    "' formaction='search.php'>" . 
    $u->item(0)->childNodes->item(0)->nodeValue . 
    "</button>" . 
   "<a href='" . 
    $z->item(0)->childNodes->item(0)->nodeValue . 
    "' target='_blank'>" .
    $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
    }
  else
    {
    $hint=$hint . "<br /><button type='submit' name='code' value='" . 
    $u->item(0)->childNodes->item(0)->nodeValue . 
    "' formaction='search.php'>" . 
    $u->item(0)->childNodes->item(0)->nodeValue . 
    "</button>" . 
   "<a href='" . 
    $z->item(0)->childNodes->item(0)->nodeValue . 
    "' target='_blank'>" .
    $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
    }
  }

在ajax中,结果图片如下。 enter image description here

但是,当我点击按钮时,不会发生任何动作。 我怎么了?

2 个答案:

答案 0 :(得分:2)

替换

formaction='search.php'

onclick='javascript:location.href=\'search.php\'';

更新2:

想提交表单试试这个

    $hint= "<form action='search.php' methos='post' >"
    ."<button type='submit' name='code' value='" . 
    $u->item(0)->childNodes->item(0)->nodeValue . 
    "' >" . 
    $u->item(0)->childNodes->item(0)->nodeValue . 
    "</button>" . 
   "<a href='" . 
    $z->item(0)->childNodes->item(0)->nodeValue . 
    "' target='_blank'>" .
    $y->item(0)->childNodes->item(0)->nodeValue . "</a>".
    "</from>";

答案 1 :(得分:1)

应该而且您还需要对<form>标记应用操作而不是按钮操作

action='search.php'

而不是

formaction='search.php'

您可以在form标记内添加代码,将action='search.php'添加到其中,所以看起来像

$hint= "<form action='search.php' methos='post' >";
$hint .=your code here 
  ....
$hint .='</form>';
相关问题