I am trying to make an AJAX jsonp request to a temporary source of data for testing. This is the code I am using:
$('#search').click(function (event) {
$.ajax({
url: "http://api.test.com/v1/",
type: "GET",
contentType: "application/json",
dataType: "jsonp",
data: {q:$("#keyword").val()},
timeout: 5000,
beforeSend: function () {
$('#content').fadeTo(500, 0.5);
},
success: function (data, textStatus) {
$('html, body').animate({
scrollTop: '0px'
}, 300);
$('#content').html(data.objects[0].category+'<br>'+data.objects[0].company);
},
error: function (x, t, m) {
if (t === "timeout") {
alert("Request timeout");
} else {
alert('Request error');
}
},
complete: function () {
$('#content').fadeTo(500, 1);
}
});
});
When ever I try and run the command I get the following error:
Uncaught SyntaxError: Unexpected token :
I am new to jquery and ajax generally, and this has me stumped. Where have I gone wrong?