I have recently been faced with a problem. I have a script that adds an item to shopping cart of my Opencart via ajax post and adds the results into a div. However I seem to be getting a response that is different of the set response which is
"Success: You have added <a href="%s">%s</a> to your <a href="%s">shopping cart</a>!"
This is the response that I am getting in my div:
{"success":"Success: You have added
<a href="\"http:\/\/mystore.org\/store\/index.php?route=product\/product&product_id=50\"">
Apple<\/a> to your</a><a href="\"http:\/\/mystore.org\/store\/index.php?route=checkout\/cart\"">
shopping cart<\/a>!","total":"3 item(s) - $20.99"}
</a>
This is my script:
$(document).ready(function(){
$("#addform").submit(function() {
$.post($("#addform").attr("action"), $("#addform").serialize(), function(data){
$("#result").empty().slideDown("slow").append(data);
});
return false;
});
});
I am just a beginner so if possible please provide detail.
Thank you very much
You are getting a json response, to get the success message you need this -
$("#addform").submit(function() {
$.post($("#addform").attr("action"), $("#addform").serialize(), function(data){
// parse json response
data = $.parseJSON(data);
// get success message with data.success and append it to results
$("#result").empty().slideDown("slow").append(data.success);
});
return false;
});