JQuery Form Plugin File Upload using POST redirects to POST response

后端 未结 5 1690
轮回少年
轮回少年 2021-01-19 01:34

Please help guys, This one is a major BLOCKER!

I have a project that uses NodeJS + jQuery Form Plugin + Typescript in which I am trying to do a file

5条回答
  •  长发绾君心
    2021-01-19 02:37

    Are you asking why am I getting the error:

    XMLHttpRequest cannot load localhost/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:8080' is therefore not allowed access.

    If so then what you need on your localhost server (assuming that is also Node) is a header set on the response from localhost to allow the Origin of localhost:8080 to access this resource like this:

    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8080');
    

    Or perhaps you are actually trying to request from the same server but forgot that 8080 is your test server: if so then in your test you should list your URL as

    $.ajax("http://localhost:8080", { //....
    

    or to repeat the current origin:

    $.ajax( window.location.origin,{ // ....
    

    Your last alternative to avoiding this (if you can't set the Origin policies on the response) is to use a jsonp service which is less strict but also less featured, but that's not appropriate for your task so I won't go into that.

    Either way once you get past the Origin policy you'll have other hurdles as @zeroflagL mentions. Here's a method that might suit you: How to handle cross domain iframe file upload json response?

提交回复
热议问题