jquery - Change inner text after ajax call back doesn't work? -


i have ten buttons on page, create foreach loop on page.

i have problem in changing inner text jquery.

let me explain elements

     <a class="pr-endorse" id="<%=product.confectionaryproductid %>">         <i class="pr-add"></i>         <span>+</span>         <span class="pr-likes"><%=product.endorsementcount %></span>     </a> 

this 1 of button elements.

and ajax function submit user

      $(document).ready(function () {         $(".pr-endorse").click(function () {             debugger;             var productid = $(this).attr("id");             var confid = $("#confectioneryid").val();             var countnumber = $(this).find(".pr-likes").html();             $.ajax({                 url: '<%: url.action("endorsement","confectionery")%>',                 data: { productid: productid, itemid: confid },                 type: "post",                 async: true,                 cache: false,                 success: function (result) {                      debugger;                     $(this).find(".pr-likes").text(result.endorescount);                     alert(result.endorescount);                  },                 error: function (xhr) {                     alert(xhr);                 } 

i thing part of code should solve

  $(this).find(".pr-likes").text(result.endorescount); 

but not work ?

i'll give try, should this

$(document).ready(function () {     $(".pr-endorse").click(function () {          var self        =         var productid   = self.id;         var confid      = $("#confectioneryid").val();         var countnumber = $(this).find(".pr-likes").html();          $.ajax({             type : "post",             url  : '<%: url.action("endorsement","confectionery")%>',             data : {                 productid : productid,                 itemid    : confid             },             datatype : 'json',             success : function (result) {                  $(self).find(".pr-likes").text(result.endorescount);                 alert(result.endorescount);              },             error : function (xhr) {                 alert(xhr);             }         });     }); }); 

note this inside success function not element clicked, , return object you'd want set datatype, if jquery parse if headers correct.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -