Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在将表单数据发布到iframe之后获取响应数据_Javascript_Jquery_Iframe_Form Submit - Fatal编程技术网

Javascript 如何在将表单数据发布到iframe之后获取响应数据

Javascript 如何在将表单数据发布到iframe之后获取响应数据,javascript,jquery,iframe,form-submit,Javascript,Jquery,Iframe,Form Submit,我有这个html: <form class="form-control" target="upload-profile-picture" action="<external link>" method="post" enctype="multipart/form-data"> <input type="file" name="file" data-bind="event: { change: function(vm, ev) { uploadImage(ev

我有这个html:

<form class="form-control" target="upload-profile-picture" action="<external link>" method="post" enctype="multipart/form-data">
    <input type="file" name="file" data-bind="event: { change: function(vm, ev) { uploadImage(ev, $element.files[0]);} }" />
    <iframe id="upload-profile-picture" name="upload-profile-picture" class="hidden"></iframe>
    <button type="submit" id="submit" class="hidden"></button>
</form>
我得到一个错误:

SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://localhost:65147" from accessing a cross-origin frame.
表单操作是将图像发布到另一个域中托管的API,我想获取响应信息,但收到此错误。它不能通过ajax发布文件,因为API不支持

如何获取响应数据

更新:

当我使用ajax时:

$.ajax({
    type: "POST",
    url: "<external link>",
    data: {file: file},
    success: function (result) {
        console.log(result);
    },
    dataType: 'json',
    processData: false,
    contentType: 'multipart/form-data',
});

关于AJAX,API到底不支持什么?是否有错误消息?iframe从何处获取其src?这是访问API的一种非常糟糕的方式,因此您必须研究是否可以使用AJAX。我没有API的权限,我只有调用它的权限。请尝试在
$.ajax({
    type: "POST",
    url: "<external link>",
    data: {file: file},
    success: function (result) {
        console.log(result);
    },
    dataType: 'json',
    processData: false,
    contentType: 'multipart/form-data',
});
errorCode: 500
message: "the request was rejected because no multipart boundary was found"
reason: "API error"
stackTrace: null