Got an issue with my ajax, Here is my code
var sortTable = function() {
$("#tableid tbody tr").detach().sort(function(a, b) {
var dataA = $(a).find("td:eq(3)").text().trim();
var dataB = $(b).find("td:eq(3)").text().trim();
return parseFloat(dataA.substring(1)) - parseFloat(dataB.substring(
1));
}).appendTo('#tableid');
};
// var contentType ="application/x-www-form-urlencoded; charset=utf-8";
//
// if(window.XDomainRequest) contentType = "text/plain";
$.ajax({
beforeSend: function (xhr){
xhr.setRequestHeader("Content-Type","application/json");
xhr.setRequestHeader("Accept","application/json");
},
type: 'GET',
crossDomain: true,
dataType: 'jsonp',
url: 'Url here' + var,
success: function(json) {
//var json = $.parseJSON(data);
for (var i = 0; i < json.results.length; i++) {
var section = json.results[i].name;
var tid = json.results[i].Id.slice(1);
var price = json.results[i].minPrice;
var url = json.results[i].url;
var button =
"<a class='btn btn-info'>Buy Now</a>";
$("#tableid").append("<tr><td><img id='theImg' src='/assets/logo.png'/></td><td><b>" + section +
"</b></td><td><b> In Stock </b></td><td><b>£" + price + "</b></td><td><b>N/A</b></td><td><b>£" + price +"</b></td><td><b>" + button + "</b></td></tr>");
$("#tableid").find(".btn.btn-info").click(function() {
location.href = $(this).attr("data-url");
});
}
sortTable();
},
error: function(error) {
console.log(error);
}
});
Now when i try and load the thing (debuggers in both the error and the success) the debugger activates in the error function, Stating that its status 200 etc etc. (the data is pulled back fine in postman)
In the console i get
Uncaught SyntaxError: Unexpected token :
How can i fix this? obviously nothing being appended to the table because of this.
Sam