jQuery脚本工作,只是不在WordPress中工作

时间:2017-07-23 03:54:03

标签: javascript php jquery sql wordpress

所以我现在已将我的代码编辑为以下内容:

我一直在努力让这个脚本运行,因为我对jQuery很新。我得到它应该工作的工作。但是只要我将php文件包含到我的WordPress安装中,它就无法正常工作。

<?php
include 'arter.php'; 
?>

<form action="" id="searchForm">
    <label>Art :</label>
    <input list="arter" name="art">
    <datalist id="arter">
    <?php echo $art;?>
    </datalist><br /><br />
    <input type="submit" value="Søg">
</form>
<!-- the result of the search will be rendered inside this div -->
<div id="result"></div>

<script>

$.noConflict();
jQuery(document).ready(function($){
    // now you can use jQuery code here with $ shortcut formatting
    // this will execute after the document is fully loaded
    // anything that interacts with your html should go here

$("#result").append( "loaded jQuery version ($): " + $.fn.jquery + "<br>" );

    $( "form" ).submit(function( event ) {

        var species = $("input:first").val();

        var posting = $.post( "resultat.php", { art: species });

            posting.done(function( data ) {
           $("#result").html( "Data indlæst: " + data + "<br>" );
            });

        event.preventDefault();
    });

    $( document ).ajaxComplete(function() {
    $( "#result" ).append( "Triggered ajaxComplete handler." );
});

});
</script>

现在,下面添加的部分可以帮助我了解通话结束的时间。单独加载页面和调用句柄并按原样执行。但是通过Wordpress加载页面只是处理基础知识。所有提交操作都不是由wordpress处理的,下面的代码只是继续循环执行。

  

$(document).ajaxComplete(function(){       $(“#result”)。append(“Triggered ajaxComplete handler。”);

resultat.php:

<?php
include 'con.php';

// error_reporting(-1); // reports all errors
// ini_set("display_errors", "1"); // shows all errors
// ini_set("log_errors", 1);
// ini_set("error_log", "php-error.log");

// set the PDO error mode to exception
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

function resultat($conn) {

        if ($_POST['art'] == '*') {
            $sql = "SELECT `id`, `navn`, `team`, `art`, `vaegt`, `dato` FROM `indvejninger` ORDER by `art`, `vaegt` DESC";
        }
        else {
            $sql = "SELECT `id`, `navn`, `team`, `art`, `vaegt`, `dato` FROM `indvejninger` WHERE `art`=:art ORDER by `art`, `vaegt` DESC LIMIT 10";    
        }

        $stmt = $conn->prepare("$sql");
        $stmt->bindParam(':art', $_POST["art"]);
        $stmt->execute();

        while ($arr = $stmt->fetch(PDO::FETCH_ASSOC)) {
            echo "<TR> <TD>" . $arr['navn'] . "</TD>";
            echo "<TD>" . $arr['team'] . "</TD>";
            echo "<TD>" . $arr['art'] . "</TD>";
            echo "<TD>" . $arr['vaegt'] . "</TD>";
            echo "<TD>" . $arr['dato'] . "</TD></TR>";
            }
     }    

?>

    <div id="resultat">
    <TABLE style="width:100%" id="result">
    <TR> <TD>Navn:</TD> <TD>Team:</TD> <TD>Art:</TD> <TD>Vægt:</TD> <TD>Dato:</TD></TR>
    <?php resultat($conn);  ?>
    </TABLE>
    </div>

我真的希望有人能帮我解决这个问题吗?

0 个答案:

没有答案