Jquery 如何使用静态网页从服务器下载文件?
我使用的是静态网页。单击按钮时,我想从web浏览器下载文件。我使用的是Jquery 如何使用静态网页从服务器下载文件?,jquery,asp.net,ajax,json,jqgrid,Jquery,Asp.net,Ajax,Json,Jqgrid,我使用的是静态网页。单击按钮时,我想从web浏览器下载文件。我使用的是json、jquery和jqgrid。您能告诉我如何使用json、jquery和jqgrid下载吗 这是我的密码: string filePath = ConfigurationManager.AppSettings["myFilePath"].ToString(); Guid g; g = Guid.NewGuid(); string strFilename = EmpId + g + ".xml"; string Mapp
json
、jquery
和jqgrid
。您能告诉我如何使用json
、jquery
和jqgrid
下载吗
这是我的密码:
string filePath = ConfigurationManager.AppSettings["myFilePath"].ToString();
Guid g;
g = Guid.NewGuid();
string strFilename = EmpId + g + ".xml";
string Mappingpath = HttpContext.Current.Server.MapPath(filePath + strFilename);
xmlDoc.Save(Mappingpath);
return filePath + strFilename;
我的jqgrid
代码是
$.ajax({
type: "POST",
url: "EmployeeDetails.aspx/savefile_XML",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{'getdata':" + JSON.stringify(getdata) + "}",
success: function (msg) {
window.open(msg.d, "Employyees");
var link = document.createElement("EmployeeDetails");
var fileName = data.substring(data.lastIndexOf('/') + 1);
link.download = fileName;
link.href = data;
link.click();
alert("downloaded");
},
在该代码中,windows.open()可以正常工作,但我的文件不是从web浏览器下载的。我在Internet Explorer中出错;这是JavaScript运行时错误:对象不支持属性或方法lastIndexOf
我的问题是,当用户单击按钮以显示“保存文件位置”窗口时,如何使用此代码下载文件。您好,希望这有助于重播。但是,当我单击webbrowser中下载的行详细信息时,我想知道您的数据变量是否为空\n未定义。您能在脚本中放入console.log并检查“data”的值吗?另外,运行Fiddler\Browser Developer Tools并观察网络调用运行此脚本时,是否从JSON调用中返回404\500 HTTP代码?或者您得到的是200?您将数据类型指定为json。json对象在我编写代码时不支持lastindexof..plz建议我。。我试过很多密码。。