I need to call a external URL (not in my development server) that returns JSON response. Doing some research I found this and this post and tried almost every, right now my code is this:
$("#query").on("keyup", function(e) {
if (e.which !== 32) {
var value = $(this).val();
var noWhitespaceValue = value.replace(/\s+/g, '');
var noWhitespaceCount = noWhitespaceValue.length;
if (noWhitespaceCount % 3 === 0) {
var request = $.ajax({
type: 'GET',
data: "text=" + $(this).val(),
url: "http://192.168.0.159:3000/products/search/all",
success: function(data) {
console.log(data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
request.abort();
}
});
}
}
});
But it's not working, so what is the best way to achieve this?