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

前端 未结 4 2171
我寻月下人不归
我寻月下人不归 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:11

    I was having the same problem, with an identical error message. In my case it was caused by the server setting a Feature-Policy header with sync-xhr: none. Removing this directive fixed the problem.

    0 讨论(0)
  • 2021-01-01 19:12

    You can test your webpages with Chrome on Windows like this

    chrome.exe --allow-file-access-from-files
    
    0 讨论(0)
  • 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");
    
    0 讨论(0)
  • 2021-01-01 19:24

    I had this problem literally a few minutes ago. The problem is that you need to set async:false to async:true. I'm not sure exactly why this works, I guess because HTML5 is newer than XML.

    Error is a bit different on this site but I think it's similar: JavaScript console.log causes error: "Synchronous XMLHttpRequest on the main thread is deprecated..."

    Update

    Hi, I'm back with some new and improved information. The Cross-Origin occurs with ports as well as domains/IPs, and will probably be in place with most decent browsers. If you want to know what is happening, try changing the IP to localhost or vice versa (if you are using localhost). Keep in mind this issue can occur when you are using different ports as well. For a quick fix, make sure that in the headers from whatever the back-end server is that you are putting out the correct Access-Control header response.addHeader("Access-Control-Allow-Origin", "*");.

    Code is derived from this question

    0 讨论(0)
提交回复
热议问题