weixin_33697898 2014-10-30 11:56 采纳率: 0%
浏览 5

无法检索Ajax请求

I'm not too familiar with Ajax but I believe I grasp the basics. So I'm sending an id which I retrieve from an element to a php page but I can't seem to retrieve the id being send.

My javascript:

function ListPart(part) {
        var imgdata = part;
        $.ajax({
            url: "components.php",
            type: "POST",
            data: { id : imgdata },
            dataType: "text",
            success: function(imgdata) {
                alert(imgdata);
            }
        });
        return false;
    }

My components.php:

<?php
    if(isset($_POST["id"])) {
        echo $_POST["id"];
    } else {
        echo "not found";
    }
?>

Am I missing something small? Also I would like to know in that alert(imgdata) I get the whole document's html and not just the id? Is there a reason for this?

PS: The "not found" is not even being displayed. Although the alert in the success function does execute.

Any help will be appreciated!

Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?