문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top