从php获取javascript的结果

从php获取javascript的结果,javascript,php,html,Javascript,Php,Html,首先,早上好。 我正在开发一个搜索表单,它调用一个连接到mysql数据库的php来获取结果 我的问题是我试图从我的php中得到结果。。。 当我在php上搜索并调用函数时,它会显示在另一个页面上。。。 有没有一种方法知道如何从php到javascript获取数据 我的html搜索表单: <div class="quicky-search pesquisaa-form"> <form id="pesquisaa" action

首先,早上好。 我正在开发一个搜索表单,它调用一个连接到mysql数据库的php来获取结果

我的问题是我试图从我的php中得到结果。。。 当我在php上搜索并调用函数时,它会显示在另一个页面上。。。 有没有一种方法知道如何从php到javascript获取数据

我的html搜索表单:

<div class="quicky-search pesquisaa-form">
                            <form id="pesquisaa" action="" method="POST" autocomplete="off">
                             <fieldset>
                                <input type="text" name="query" placeholder="Pesquisar"/>
                                <button type="submit" value="Search" class="submity-search"><span class="icon-search"></span></button>
                             </fieldset>
                            </form>
                         </div>

html中的我的脚本:

<script>
$(function(){
$('#pesquisaa').validate({
submitHandler: function(form) {
    $(form).ajaxSubmit({
    url: 'assets/email/pesquisar-cdd.php',
    success: function() {
    $('#pesquisaa').hide();
    $('#pesquisaa-form').append(PS: I NEED THE RESULT INSIDE HERE TO SHOW ON MY HTML PAGE)
    }
    });
    }
});         
});
</script>

$(函数(){
$('#pesquisaa')。验证({
submitHandler:函数(表单){
$(表格).ajaxSubmit({
url:'assets/email/pesquisar cdd.php',
成功:函数(){
$('#pesquisaa').hide();
$('#pesquisaa form').append(注:我需要这里的结果显示在我的HTML页面上)
}
});
}
});         
});
现在我的PHP:

<?php
    mysql_connect("localhost", "root", "password") or die("Error connecting to database: ".mysql_error());
    /*
        localhost - it's location of the mysql server, usually localhost
        root - your username
        third is your password

        if connection fails it will stop loading the page and display an error
    */

    mysql_select_db("atuacdd") or die(mysql_error());
    /* tutorial_search is the name of database we've created */
?>
<?php
    $query = $_POST['query']; 
    // gets value sent over search form

    $min_length = 3;
    // you can set minimum length of the query if you want

    if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then

        $query = htmlspecialchars($query); 
        // changes characters used in html to their equivalents, for example: < to &gt;

        $query = mysql_real_escape_string($query);
        // makes sure nobody uses SQL injection

        $raw_results = mysql_query("SELECT * FROM cidades
            WHERE (`title` LIKE '%".$query."%') OR (`text` LIKE '%".$query."%')") or die(mysql_error());

        // * means that it selects all fields, you can also write: `id`, `title`, `text`
        // articles is the name of our table

        // '%$query%' is what we're looking for, % means anything, for example if $query is Hello
        // it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
        // or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'

        if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following

            while($results = mysql_fetch_array($raw_results)){
            // $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop

                echo "<p><h3>".$results['title']."</h3>".$results['text']."</p>";
                // posts results gotten from database(title and text) you can also show id ($results['id'])
            }

        }
        else{ // if there is no matching rows do following
            echo "Desculpe não atuamos nesta Cidade desejada!";
        }

    }
    else{ // if query length is less than minimum
        echo "Tamanho Minimo é ".$min_length;
    }
?>
使用

而不是

success: function(){

}

您将得到php端的数据回音。

您能得到上面的代码并为我制作吗?我很困惑,抱歉,它仍然不起作用:$('pesquisaa').hide()如何$('pesquisaa form').append('p class='alert alert success'>Obrigado,recebmos seu Email com successo.

))success:function(data){$('pesquisaa').hide();$('pesquisaa form').append(data)});对于一些不显示结果和“$('#pesquisaa').hide();”这个函数在显示结果之后隐藏搜索表单我将如何发送所有代码?我在我写的第一篇文章中有HTML表单above@Doorknob你说的“AJAX”是什么意思???
success: function(){

}