简体   繁体   中英

Can't edit recieved PHP data from ajax call

I'm using ajax to get data from a database. The server-side language is PHP. In the PHP file that I'm referencing in the ajax call, I echo a div with database information in it. However, when I recieve the data in the browser, I can't make changes to the data using jQuery. For example, when I try to target a specific element:

$(data).appendTo("#container"); //appending recieved data onto page

$(data).find("#delete-button").click(function() { 
$(this).hide();
}); //trying to hide button within appended data when I click it

it doesn't do anything. Why is it that I can't edit the recieved PHP code?

I was able to recieve the data using the ajax call, but I just can't edit the data I'm recieving using jQuery.

Wrapping the data string in $() the second time is not targeting what you actually appended previously... it is a new fragment instance only in memory

After the append() you can query the element directly in the dom:

$("#delete-button").click(function() { 
    $(this).hide();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM