0

Hi all,

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.

3
Contributors
8
Replies
55
Views
2 Years
Discussion Span
Last Post by jstfsklh211
1

your data should be an array

data : [["id", imgdata], ["var2", val2]]

Edited by jstfsklh211

0

Hi,

Sorry for the delay in replying. Can you describe in a non-technical way what it is that you are wanting to achieve?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.