How do I use data passed back in the response from ajax jQuery? -
I try to use the response from jQuery AJAX request to set the inner HTML of a div with a specific ID I am doing I'm using this code:
$ (". Show_comments"). Click (function () {var nameName = $ (this) .closest ("article") .tr ('id') $ .ajax ({url: "commentView.php", data: {'graphname': graphname} , Cache: incorrect, data type: "html", // so that it is automatically parse it as HTML success: function (response) {$ (this) .clostest ("article"). ("Comments "). Html (feedback);}}); But it does not appear at all, I have tried to googling around, but whatever I can find is I say that I will do it I am ... I have tested in firebug and the AJAX request I want to give me the exact feedback ... but I can not use it to set the Devell's internal HTML for feedback! / P>
There is another scope for your AJAX success handler and this is not Do not think so. Change your code: var articlename = $ (this) .clostest (" Articles "). (". Articlename "Search) .attr ( 'id'), it = it; $ Ajax ({url: "commentView.php", data: {articleName}: articleName}, cache: incorrect, data type: "html", // so that it parsed it as html success: function (response) {$ (That) .clostest ("article"). ("Comments"). Html (feedback);}}); What I changed: I added the that variable which indicates this for example and instead in the success handler Uses it. How do you debug it yourself: if you do output console.log (this) and console.log ($ (this) .closest ("article") Have tried .find ("comments")); You will see that it returns an incorrect object (in the first case) and nothing else in the other.
Comments
Post a Comment