Ajax request returns 200 OK, but an error event is fired instead of success

后端 未结 16 2392
难免孤独
难免孤独 2020-11-22 04:12

I have implemented an Ajax request on my website, and I am calling the endpoint from a webpage. It always returns 200 OK, but jQuery execut

16条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 04:40

    This is just for the record since I bumped into this post when looking for a solution to my problem which was similar to the OP's.

    In my case my jQuery Ajax request was prevented from succeeding due to same-origin policy in Chrome. All was resolved when I modified my server (Node.js) to do:

    response.writeHead(200,
              {
                "Content-Type": "application/json",
                "Access-Control-Allow-Origin": "http://localhost:8080"
            });
    

    It literally cost me an hour of banging my head against the wall. I am feeling stupid...

提交回复
热议问题