1
我需要实现以下场景:我有一个HTML页面,其中是一个按钮和一些文本框。当我点击按钮时,我想从文本框数据创建一个xml并将这个xml发送到服务器,比服务器将这个xml作为附件返回,我将有一个另存为对话框,并且我可以在本地保存这个xml。我有以下的jquery功能,发送XML到服务器:打开保存为javascript的对话框
function GetXml() {
var xmlData = '{"xml": "<test>test</test>"}';
var contentType = "application/json";
var eDoc = "";
$.ajax({
type: 'POST',
url: 'http://localhost/xmlservice.svc/rest/GetXmlToSave',
data: xmlData,
contentType: contentType,
success: function (result) {
alert(result);
},
error: function (result) {
alert(result);
},
async: false,
});
return result;
}
但我不知道热从JavaScript从服务器返回的XML强制另存为对话框。
我可以用经典的提交按钮意识到这一点:
<form action='http://localhost/xmlservice.svc/rest/GetXmlToSave' method="POST" runat="server" >
<input type="submit"/>
</form>
但在这种情况下,我不能在客户端创建XML。
是否可以强制另存为对话框从JavaScript?
谢谢。
[使用JQuery和Ajax在ASP.Net中保存文件]的可能的重复(http://stackoverflow.com/questions/3111750/using-jquery-and-ajax-to-save-a-file-in -asp-net) – Quentin
另请参阅[this](http://stackoverflow.com/questions/15637758/django-invoking-browsers-save-as-from-an-ajax-invoked-view),[this](http ://stackoverflow.com/questions/10256050/generate-save-as-dialog-box-with-ajax-request-in-ext-js)和[this](http://stackoverflow.com/questions/7684297/ content-disposition-with-attachment-doesnt-work-for-ajax-response) – Quentin
另请参阅:http://stackoverflow.com/questions/13405129/javascript-create-and-save-file –