页面是使用Angular 2+进行的一项小型调查(共12个问题),并带有名称的最终形式-电子邮件输入,一个检查按钮和一个用于发送结果的按钮。该按钮调用Parse.cloud.run函数,该函数创建PDF并在base64中返回它,然后我们存储数据并通过另一个parse.cloud函数发送电子邮件。好的,此页面在Chrome和Firefox中运行完美。在Microsoft Edge中,它永远不会起作用。在Safari中,几乎每次都可以工作(仅在一个imac中,我们就会遇到与Edge中相同的问题)。
问题是,当调用该Parse.cloud函数时,浏览器尝试将您重定向到以输入作为参数的url(例如:url+inputNameN=dsfdsf&inputEmailN=pepe@pepe.es&inputCheckN=on),并结束出现404 Not Found错误(很明显,该页面不存在)。
经过几次研究,我在这方面没有发现任何东西。我不了解这种行为及其原因。
这是一个简短的代码,当它到达错误发生时的“ Parse.Cloud.run('create-pdf',formData)”行时。
onSend(): void {
if (!this.inputName || this.inputName.length==0) {
//code
}
if (!this.inputEmail || this.inputEmail.length==0) {
//code
}
if (!this.inputCheck) {
//code
}
var email = this.inputEmail.toLowerCase();
var emailRegEx1 = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/i;
var emailRegEx2 = /^.+@.+\.[a-z]{2,4}$/i;
var validEmail=emailRegEx1.test(email) && emailRegEx2.test(email);
if (!validEmail) {
//code
}
var formData = {
"text1" : this.temporalTitle,
"text2" : this.temporalBody,
"text3" : this.interlude,
"firstAnswer" : this.firstAnswer,
"secondAnswer" : this.secondAnswer,
"thirdAnswer" : this.thirdAnswer,
"fourthAnswer" : this.fourthAnswer,
"fifthAnswer" : this.fifthAnswer,
"sixthAnswer" : this.sixthAnswer,
"seventhAnswer" : this.seventhAnswer,
"eigthAnswer" : this.eigthAnswer,
"ninthAnswer" : this.ninthAnswer,
"tenthAnswer" : this.tenthAnswer,
"higth": this.resultado,
"left": this.leftResult,
"rigth": this.rightResult,
"on": 1
}
Parse.Cloud.run('create-pdf', formData)
.then((data)=> {
if (!data.error) {
var base64data = {
base64: data.message.base64
};
var d = new Date();
var name = "_resultado_cuestionario" + d.getTime() + ".pdf";
var parseFile = new Parse.File(name, base64data);
parseFile.save().then((p)=> {
let result = Parse.Object.extend("Results");
let myResult = new result();
myResult.set("answer1",this.answer1);
myResult.set("answer2",this.answer2);
myResult.set("answer3",this.answer3);
myResult.set("answer4",this.answer4);
myResult.set("answer5",this.answer5);
myResult.set("answer6",this.answer6);
myResult.set("answer7",this.answer7);
myResult.set("answer8",this.answer8);
myResult.set("answer9",this.answer9);
myResult.set("answer10",this.answer10);
myResult.set("answer11",this.answer11);
myResult.set("answer12",this.answer12);
myResult.set("sum",this.resultado);
myResult.set("email",this.inputEmail);
myResult.set("name",this.inputName);
myResult.set("pdf",parseFile);
myResult.save()
.then((ok)=>{
var formData = {
"mail": this.inputEmail,
"subject": "Envío de informe RMG (en pruebas)",
"message": this.informe,
"urlFile": ok.attributes.pdf._url
}
Parse.Cloud.run('send-mail', formData)
.then((data)=> {
if (data.success) {
//code
}
else {
//code
}
});
})
.catch((error)=>{
console.log(error);
})
}, function(error) {
console.log('error en la imagen 2' + error)
});
}
else {
//swal("Error!!", data.message, "error");
}
});
}
这是html部分:
<div class="container">
<div class="row">
<div class="col">
<h4>Para recibir su informacion gratuita rellene los siguientes campos:</h4>
<br>
<form #mailForm="ngForm">
<div class="form-group">
<label for="exampleInputName1">Nombre Empresa</label>
<input type="text" class="form-control" id="exampleInputName1" [(ngModel)]="inputName" name="inputNameN" placeholder="nombre empresa">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Mail</label>
<input type="email" class="form-control" id="exampleInputEmail1" [(ngModel)]="inputEmail" name="inputEmailN" aria-describedby="emailHelp" placeholder="mail">
<small id="emailHelp" class="form-text text-muted">Nunca compartiremos su mail con nadie.</small>
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1" [(ngModel)]="inputCheck" name="inputCheckN">
<label class="form-check-label" for="exampleCheck1">Check me out</label>
</div>
<button type="submit" class="btn btn-primary" (click)="onSend()" ng-disabled="sending">Enviar</button>
</form>
</div>
</div>
</div>
这是后端中的parse.cloud函数
Parse.Cloud.define('create-pdf', function (req, res) {
let object = pdfConf.validate(req.params.text1, req.params.text2,req.params.text3,
req.params.firstAnswer,req.params.secondAnswer,req.params.thirdAnswer,req.params.fourthAnswer,req.params.fifthAnswer,
req.params.sixthAnswer,req.params.seventhAnswer,req.params.eigthAnswer,req.params.ninthAnswer,req.params.tenthAnswer,
req.params.higth, req.params.left, req.params.rigth, req.params.on);
if (object.error) {
res.error( { error: object.error, message: object.message } );
return;
}
let pdf = pdfConf.createPdf(object)
.then((success) => {
res.success( success );
})
.catch((e) => {
res.error( e );
});
});
如果需要,可以在这里尝试页面:https://rmg.aratech.org。正如我所说,这是一个包含12个问题和最终表格的调查,选择任何答案,并在末尾添加假名称和假电子邮件。
任何帮助将不胜感激。