Ajax提交表单数据类型问题
我在使用ajax提交html输入表单时遇到了一些问题,而且datatype
似乎有问题。
的背景:
- 从
app engine
向aws
发送输入表单 - 在
aws
上创建一个pdf
文件,将其保存在s3
,然后将超链接发送回app engine
- 在
app engine
端,生成带有超链接的html页面 - 如果ajax调用成功,则重定向到在
Step 3
创建的页面
输入表格:
Ajax调用:
$(document).ajaxStart(function(){ alert('start'); }); $.ajax({ type: "post", url: "/pdf.html", data: $('#pdf_post').serialize(), dataType: "html", success: function () { alert('success'); window.location = "/pdf.html"; }, error: function (data) { console.log(data) alert('error'); }, });
根据ajax
调用,我的浏览器将被重定向到带有超链接的页面。 但这从未发生过,结果与dataType
值有关:
-
dataType: "html"
,ajax
成功触发,但我收到错误消息:405 Method Not Allowed The method GET is not allowed for this resource.
-
dataType: "json"
,ajax
错误被触发 -
dataType: "data"
,ajax
错误触发
我检查了服务器端,看起来无论我选择什么数据类型,总是生成pdf。 此外,当从console.log(data)
触发ajax error
时,我可以看到具有正确超链接的网页。 谁能给我一些建议? 谢谢!