简体   繁体   中英

Trying to send a response from express to jquery-iframe-transport

I'm trying to set up a simple file upload using jquery-ifram-transport and nodejs the problem is i keep getting the error caught SecurityError: Blocked a frame with origin "https://localhost:8081" from accessing a frame with origin "serverURL". Protocols, domains, and ports must match.

Here is my clients ajax code from the client

var uploadXhr = $.ajax($scope.nodeSocketUrl + '/upload?tenant=qa',{
                    data: $(':text', form).serializeArray(),
                    files: $('#presentationFileUpload'),
                    type: 'POST',
                    iframe: true,
                    processData: false,
                    context: this
                });

Here im just having a hard time getting this plugin to work with formidable I would like for a request to be sent back to the client like hey file has been uploaded something like this.

form.on('end',function(){
res.header({'content-type': 'text/html'});
        res.send('<html><textarea data-type="application/json">{"ok": true, "message": "Thanks so much"}</textarea></html>');
});

Anyone who knows how to sent back a request from express to a jquery-iframe-transport ajax request would be a huge help here.

Update Here are my current cors settings

app.all('/*', function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Credentials', true);
    res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
    res.header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Authorization');
    next();
});

Are you using Express?

Try this:

app.all('*', function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  next();
 });

You need to enable CORS headers for it to work properly.

http://enable-cors.org/index.html

Edit:

Sometimes you need to configure your browser. Localhost behaves differently than actual domains.

Start Chrome with these settings: --disable-web-security

Read more about it here:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM