检索与jQuery AJAX的数据,而无需在PHP刷新页面 [英] Retrieving Data with jQuery AJAX Without Reloading Page in php

查看:112
本文介绍了检索与jQuery AJAX的数据,而无需在PHP刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经试图阻止刷新页面上点击选择选项,但是当我停止刷新页面,然后数据无法获得。

I have try to stop refresh page on click on select option but when I stop refresh page then data can not get.

在这里code

echo "<form name='frmtopdevotees' method='post' action='topuser_load.php'>
                <h4>select month  <select id='seldrp' name='themonth' OnChange ='document.frmtopdevotees.submit()'>     


                        $optionsmonths
                </select> 
                <select name='topdevotees' id='seldrp' OnChange ='document.frmtopdevotees.submit()'>
                        <option value=10 $M10>Top 10</option>
                        <option value=20 $M20>Top 20</option>
                        <option value=50 $M50>Top 50</option>
                        <option value=100 $M100>Top 100</option>
                </select>   </h4>               
        </form>";
?>

<script>
    $('frmtopdevotees').submit(function (e) {
        e.preventDefault();
        return false;
    });

    $('themonth').onchange(function () {
        $.ajax({
            var value = $('themonth').val();
                    type: 'post',
            data: {
                topdevotees: topdevotees,
                themonth: themonth
            },
            url: "topuser_load.php?topdevotees=" + topdevotees + "&themonth=" + themonth,
            success: function (response) {
                $('themonth').append(response);

            }
        });
    });

</script>

当我删除的onChange ='document.frmtopdevotees.submit(),然后页面停止更新,但不是数据的变化。

when I remove Onchange = 'document.frmtopdevotees.submit()' then page stop to refresh but not data change.

推荐答案

修改名称在阿贾克斯ID

$('#seldrp').onchange(function(){
   ^     ^
// ajax here                          
});

和你有语法错误在阿贾克斯。

And you have syntax errors in ajax.

   var themonth = $('#seldrp').val();
   var topdevotee = $('#topdevotees').val();//topdevotess should be the id of 2nd select box.
   $.ajax({            
        type: 'post',
        data: {
            topdevotees: topdevotees,
            themonth: themonth
        },
        async:false,// this line for waiting for the ajax response.
        url: "topuser_load.php?topdevotees=" + topdevotees + "&themonth=" + themonth,
        success: function (response) {
            $('themonth').append(response);
            $('#frmtopdevotees').submit();

        }
    });

这篇关于检索与jQuery AJAX的数据,而无需在PHP刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆