Reputation: 221
I am using sample Node.js Zoo Chat server running at port 2300 and only longPoll functionality of its index.html client to show some broadcast info in one of my ASP.NET MVC 3 view page as follows:
Client page script:
$(document).ready(function () {
longPoll();
});
function longPoll(data) {
if (data && data.messages) {
for (var i = 0; i < data.messages.length; i++) {
var message = data.messages[i];
$('<p><b>' + message.nickname + ':</b> <span>' + message.text + '</span></p>').hide().prependTo('#messages').slideDown();
}
}
$.ajax({
cache: false,
type: "GET",
url: "http://localhost:2300/recv",
success: function (data) {
//alert(data);
longPoll(data);
},
failure: function (err) {
alert(err);
}
});
}
</script>
<h1>Live Feed</h1>
<div id="messages"></div>
The difference is that I don't post messages from a form on client page; rather, it's my MVC webapp (running at port 3000) which periodically sends POST requests to the listening Node.js server via WebRequest. I get those POST request well on server.js but the ajax GET call on client is red on firebug and does not seem to be working. I wonder why?
Upvotes: 1
Views: 548
Reputation: 21439
Because it's not the same origin, to be able to send an ajax request, domain and the port must be identical.
Upvotes: 1