1

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?

1 Answer 1

1

Because it's not the same origin, to be able to send an ajax request, domain and the port must be identical.

Sign up to request clarification or add additional context in comments.

3 Comments

Oh. then how can I capture server.js messages on this client page?
you can get the data in asp from node server and access it instead.
@zee check this answer if it was helpul

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.