弹出窗口在使用mysqli时不显示

时间:2014-06-09 11:41:40

标签: jquery popup

我正在创建一个表单,其结果应该以弹出窗口显示。

查询有效,但是当我将它与弹出窗口组合时,它并没有。 当我单独使用弹出脚本时,它不会显示弹出窗口。

所以我认为问题在于弹出窗口。

//javascript
$main .=
'<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>';
//end javascript

-

//script
<script>
$(document).ready(function() {

    $("#dialog").dialog({

      autoOpen: false,
      show: {
        effect: "blind",
        duration: 1000
      },
      hide: {
        effect: "explode",
        duration: 1000
      }
    });

    $("#select-button").click(function() {
      $( "#dialog" ).dialog( "open" );
    });
});

</script>

-

//form
 $main .= "
    <form action='' method='post'>
        <span class='formInput'>zoek:</span>
        <input type='text' name='zoekproduct' />
        <input id='select-button' type='submit' name='searchBtn' value='zoek!' />
    </form>"; 
// end form

-

// when used the button
    if(isset($_POST['searchBtn']))
    {
// query
    $statement = $connectionwebshop->prepare("
    SELECT 
        producten.productlink,
        prod_omschrijving.producttitel
    FROM
        producten
    INNER JOIN
        prod_omschrijving 
    ON
        producten.idproduct=prod_omschrijving.idproduct
    INNER JOIN
        prod_categorie
    ON
        producten.idproduct=prod_categorie.idproduct
    WHERE
        (producten.productlink LIKE ?
    OR
        prod_omschrijving.producttitel like ?
    OR
        producten.productcode like ?)
    AND
        prod_categorie.idcategorieen != 8001
    ORDER BY
        prod_omschrijving.producttitel
    ");
    $statement->error;
    $zoekproductresult ='%'.$_POST['zoekproduct'].'%';
    $statement->bind_param('sss', $zoekproductresult, $zoekproductresult, $zoekproductresult);
    $statement->execute();
$result = $statement->get_result();
//end query

-

//create popup
$main .='   
<div id="dialog" title="Resultaten selecteren" style="display: none">';
            if(($result->num_rows)>=1)
            {
            $resultaten = 'Found '.($result->num_rows).' products.<br/>';

                while ($row = $result->fetch_assoc())
                {
                $resultaten.= $row['producttitel'];
                $resultaten.='<br/>';
                }
            }
            else
            {
            $resultaten ='nothing found';
            }
        $main .= $resultaten;
    $statement->close();
    $main .='</div>';
    }

2 个答案:

答案 0 :(得分:0)

如果您希望显示弹出窗口,则需要阻止表单的默认操作(否则您的页面将重新加载)。

试试这个:

$("#select-button").click(function(e) {
  e.preventDefault();
  $("#dialog").dialog( "open" );

  // Post your stuff
  $.ajax({
      url: 'form url here',
      type: 'post',
      data: 'zoekproduct=' + $('#zoekproduct').val(), // Give your zoekproduct input an id
      success: function (result) {
          // Do success stuff here
      }
  });
});

Example

答案 1 :(得分:0)

必须在

之后打开脚本
<div id="dialog" title="Resultaten selecteren" style="display: none">';

所以你会有这个:

//create popup
$main .='   
<div id="dialog" title="Resultaten selecteren" style="display: none">';

//script
<script>
$(document).ready(function() {

    $("#dialog").dialog({

      autoOpen: false,
      show: {
        effect: "blind",
        duration: 1000
      },
      hide: {
        effect: "explode",
        duration: 1000
      }
    });

    $("#select-button").click(function(e) {
e.preventDefault();
$( "#dialog" ).dialog( "open" );

});
</script>

            if(($result->num_rows)>=1)
            {
            $resultaten = 'Found '.($result->num_rows).' products.<br/>';

                while ($row = $result->fetch_assoc())
                {
                $resultaten.= $row['producttitel'];
                $resultaten.='<br/>';
                }
            }
            else
            {
            $resultaten ='nothing found';
            }
        $main .= $resultaten;
    $statement->close();
    $main .='</div>';
    }