使用Jquery / Ajax获取数据

时间:2014-02-07 18:22:08

标签: jquery ajax post

我使用以下脚本,我认为它需要执行以下操作:

当有人点击表单中ID为“submit”的href链接时,需要调用documentblock.inc.php并提醒在documentblock.inc.php中回显的数据

但我没有得到警报。我做错了什么?

            <form action="<?php echo $domein.'/mijnpagina/bestanden/downloaden/' ?>" method="post" name="downloaditem">
                    <label><input type="checkbox" id="checker_tiny" value="ja" name="blokkeer"/> Bestand blokkeren na downloaden</label>
                    <input name="docId" id="docId" type="hidden" value="<?php echo $fetch_bestand['id']; ?>">
                    <input name="downloaditem" type="hidden" value="akkoord">
                    <a href="#" id="submit" class="button-pink">Bestand downloaden</a>
                    </form>
                    <div class="clear"></div>
                </div>

                <script>
                $(function () {
                    $('#submit').on('click', function () {
                        // stop form submission first
                        // GET VALUE OF APPID
                        var appid = $("#docId").val()
                            // GET JSON FROM PHP SCRIPT
                            $.ajax({
                                type : 'POST',
                                url : '/includes/documentblock.inc.php',
                                data: {'appid':appid}, 
                                success : function () {
                                    alert(data);
                                },
                                error : alert('test')
                            });
                    });
                });
                                    </script>     

documentblock.inc.php:

<?php echo "test"; ?>

2 个答案:

答案 0 :(得分:2)

您需要将data传递给success函数:

success : function (data) {
    alert(data);
}

答案 1 :(得分:0)

它是否喜欢这样且有效!

 <script>
function submitme(){
var docId=document.getElementById("docId").value;
var blockId=$("input[name=blokkeer]:checked").val();

$.ajax({
        type: 'POST',
        url: '/includes/documentblock.inc.php',
        data: 'docId='+docId+'&blockId='+blockId,
        success: function(msg){
            if(msg){
                document.getElementById("something2").innerHTML=msg;
            }
            else{
                return;
            }
        }
    });
} </script>