Reputation: 3
I'm just starting out with jQuery. I want to send JSON data to a server. I expect the response back as text/html.
This is my code so far:
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
</head>
<body>
<a id='json_1' href="#">Click Me!</a></div>
</body>
<script type="text/javascript">
$(document).ready(function(){
$('#json_1').click(function(){
$.post("http://www.example.com",
{ "func": "getNameAndTime" },
function(data){alert(data); },
"json");
}
);
});
</script>
</html>
When I click on the link, the alert box is displayed, showing 'Null'. Also, when I debug with FF, I can see in the console) that no data is being sent.
Can anyone spot what I may be doing wrong?
Upvotes: 0
Views: 67
Reputation: 723388
You cannot perform Ajax requests to external sites due to the same origin policy.
Upvotes: 4