NetworkError: Failed to execute 'send' on 'XMLHttpRequest'

前端 未结 4 2212
我寻月下人不归
我寻月下人不归 2021-01-01 18:45

I\'m trying to do a POST ajax request to a server hosted locally on my laptop but I can\'t seem to get any information back. When I click a button on my site (localhost), I

4条回答
  •  一个人的身影
    2021-01-01 19:13

    It was a Cross Origin Resource problem (CORS). My server was returning the correct information to me but my browser refused to accept it. To fix it I had to add 2 lines on my java server (not my site) to set them as the response header:

    yourownvariable.setHeader("Access-Control-Allow-Origin:", "origin url of your site");
    yourownvariable.setHeader("Access-Control-Allow-Methods", "GET, POST,PUT");
    

提交回复
热议问题