尝试将文件上传到Web api并保存,使用IIS在本地运行项目时,可以成功使用Chrome And IE11保存文件。
尝试保存时将项目部署到Test Env时:使用Chrome,我收到“拒绝访问”。使用IE,它可以正常工作。
如何使其与Chrome一起使用?
客户代码:
<?php
require '../../inc/dbinfo.inc';
// Retrieve the POST var:
$num = $_POST['num'];
// Create our blank object:
$obj = new stdClass();
// Combines query 1 and 3:
$sql = $conn->prepare('SELECT COUNT(*) AS sq, SUM(VdrInvoiceAmount) AS itd FROM tblVendorInvoices WHERE VendorPOID1 = ?');
$sql->bind_param('i', $num);
$sql->execute();
$hold = $sql->get_result();
$res = $hold->fetch_object();
$obj->sq = round( $res->sq, 2 );
$obj->itd = round( $res->itd, 2 );
$sql2 = $conn->prepare('SELECT POAmount AS poam FROM tblVendorPOs WHERE VENDORPOID = ?');
$sql2->bind_param('d', $num);
$sql2->execute();
$hold = $sql2->get_result();
$res = $hold->fetch_object();
$obj->pam = round( $res->poam, 2 );
// May also be handy to output JSON headers:
header('Content-type: application/json');
echo json_encode($obj);
exit();
服务器代码:
var data = new FormData();
var files = $("#fileUpload").get(0).files;
// Add the uploaded image content to the form data collection
if (files.length > 0) {
data.append("UploadedImage", files[0]);
}
// Make Ajax request with the contentType = false, and procesDate = false
$.ajax({
type: "POST",
url: uriUser + "/UploadFile",
contentType: false,
processData: false,
data: data,
success: function (data) {
try {
showMsg(MessageType.Info, data);
closeWin();
}
catch (e) {
if (e.message == "") {
showMsg(MessageType.Error, msg_error);
}
}
},
error: function (response) {
console.error('DeleteRole failed :' + response);
}
});