I am trying to do an AJAX call using JQuery, I actually have the next code:
$('#form-check').click(function(){
$.ajax({
url: "http://www.domain.com/user/checkurl/",
type: "GET",
data: $(location).attr('pathname').substring(17) + "/" + $('#urlTxt').val(),
error: function(){
$('#urlTxt').css('background','#ce2b06');
},
success: function(data){
$('#urlTxt').css('background','#83aa07');
$('#form-check').css('display','none');
$('#form-submit').css('display','block');
$('#result').append(data);
}
});
});
However when I check with Firebug I don’t get any response that I can see, I only see the message being sent and on status it says (200 – ok) but nothing gets sent back, and the Ajax call itself does the “success” clause, except that it doesn’t append the data. How can I check this? Or what am I missing?
This is a cross domain request. Browsers by default block responses from cross domain sites. You need to use jsonp as the datatype. Just google the same and you can see how it can be done using the jquery API. Stack overflow has questions around these too.
Under the same origin policy, a web page served from server1.example.com cannot normally connect to or communicate with a server other than server1.example.com. An exception is the HTML element. Taking advantage of the open policy for elements, some pages use them to retrieve Javascript code that operates on dynamically-generated JSON-formatted data from other origins. This usage pattern is known as JSONP.
also I am not sure about the way you are passing parameters to the server.. your data field should ideally resemble a json object like
also you would ideally would wanna mention the type of response you are expected to receive so that jquery can process it correctly.
This is done by setting the dataType option
dataType: “json” // can be html, xml etc