Reputation: 449
I am new to Jquery, trying to learn and written a following sample. This always returns error, what's the reason for this and how to fix this ?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function()
{
$("#btnShow").click(function()
{
$.ajax(
{
url: "www.google.com",
success: function(msg) {
alert("Success");
},
error: function (msg) {
alert("error");
}
});
});
});
Upvotes: -1
Views: 54
Reputation: 25527
Because you are trying to do a cross domain ajax request.Browser will block the request because of Access-Control-Allow-Origin
. You should either use cors
or jsonp
for cross domain request. For cors
, required server should enable cors. In the case of jsonp
, the required server should bind the response with a function in the client side.
Upvotes: 2