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;
            url: "components.php",
            type: "POST",
            data: { id : imgdata },
            dataType: "text",
            success: function(imgdata) {
        return false;

My components.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!


Recommended Answers

All 8 Replies

your data should be an array

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

Still the same 'error' occurs...

What is part ? is it a string of html or a numeric ?

Part is an id which is received from the image.

This type of id?

<img id="457" src="image.png">

Yes exactly like that! Can this produce problems?


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

can you dump your $_POST

also whats your js for grabbing the id in the first place

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.