1

Here When i click on the link get the appropriate id but change the status to all posts. Not in selected item

here html code

<div th:each="p : ${posts}">
<div id="para">
<a style="float: right;" href="#" class="decision"
th:text="${p.approved}">Approve</a> 
<input type="hidden" class="pid"  th:value="*{p.id}" /> 
</div>
</div>

when i click approve link get the id value is correct. but change status effect all other posts

Here is script

 <script>
$(document).ready(function() {
$('.decision').click(function(e) {
$.ajax({

type : 'POST',
dataType : 'json',
url : '/RealEstate/ChangeStatus.html',
data : ({

pid :$(this).siblings('.pid').val()
}),
success : function(response) {
alert(response);
$('.decision').html(response);
/* $('.decision').text(response); */
},
error : function() {
alert('Error while request..');
}
});
});
});
</script>

and the controller

@RequestMapping("/ChangeStatus.html")
@ResponseBody
public String approvDisapprove(@RequestParam("pid") String pid) {
Gson gson = new Gson();
String data = null;
Property property = propertyDAO.findById(Integer.parseInt(pid));
if (property.getApproved() == true) {
property.setApproved(false);
data = gson.toJson("False");
} else {
property.setApproved(true);
data = gson.toJson("True");
}
propertyDAO.update(property);
return data;
}

if you know about this problem please share answer

2 Answers 2

3

You need to use this reference like below :

<script>
$(document).ready(function() {
$('.decision').click(function(e) {
$.ajax({

type : 'POST',
dataType : 'json',
url : '/RealEstate/ChangeStatus.html',
data : ({

pid :$(this).siblings('.pid').val()
}),
success : function(response) {
alert(response);
$(this).html(response);
^------^ // here use this instead of .decision selector
/* $('.decision').text(response); */
},
error : function() {
alert('Error while request..');
}
});
});
});
</script>
1
  • firstly thanks for your answer but this code is note working properly because the status is not change when clicked but it's change when refreshing the page May 14, 2014 at 5:48
1
<script>
$(document).ready(function() {
    $('.decision').click(function(e) {
    $.ajax({
       type : 'POST',
       dataType : 'json',
       url : '/RealEstate/ChangeStatus.html',
       data : ({ pid :$(this).siblings('.pid').val() }),
    })
    .done(function(response) {
           alert(response);
           $(this).text(response);
       })
    .fail(function() {
          alert('Error while request..');
       });
    });
});
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.