Question

I am developing a node.js app using express. I'm listening on port 3000 of localhost for POST requests. The only way I know how to simulate a POST request is using jQuery.ajax():

$.ajax({
    url: 'localhost:3000',
    type: 'POST',
    data: {hello: 1},
    success: function (data) {
        console.log(data);
    },
    error: function (data) {
        console.log(data);
    }
});

Unfortunately, I get a the error message:

"XMLHttpRequest cannot load localhost:3000. Cross origin requests are only supported for HTTP."

What am I doing stupidly? Is there a better approach I should consider?

Was it helpful?

Solution

You can also use unix command curl to simulate the requests. With it you get horde of options.

In your case it would be curl http://localhost:3000 -d "{hello:1}" -X POST

OTHER TIPS

Use http://localhost:3000 for the url... otherwise it gets used as a directory or file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top