如何在调用json方法时提供文件夹路径位置 [英] How to provide folder path location while calling json method
本文介绍了如何在调用json方法时提供文件夹路径位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个.aspx文件,我已经在其中编写了webmethod.我已经将此.aspx文件保存在一个文件夹中.现在可以从其他文件夹.aspx文件中调用此方法.
我的JSON代码
I have a .aspx file where I have written webmethod.I have kept this .aspx file inside a folder.Now to call this method from other folder .aspx file.
My json code
$.ajax({
type: "POST",
url: "WebService.aspx/fncOwnMstDml",
data: "{ownermst:" + JSON.stringify(ownermst) + ",flag:" + -1 + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d.toString());
clear();
__doPostBack('<%= btnSch.UniqueID%>', '');
},
error: function (xhr, status, error) {
alert(xhr.responseText.toString());
}
});
我尝试过的事情:
我尝试将网址设为
What I have tried:
I have tried to put url like
url: "~/Master/WebService.aspx/fncOwnMstDml",</pre
Here Master is my folder name,fncOwnMstDml is my webmethod,WebService.aspx is .aspx page containing webmethod.I have even tried to put webservice.aspx outside of folder,and change url .
Please guide me.
Thanks in advance
推荐答案
.ajax ({ 类型:" , 网址:" , 数据:" + JSON .stringify(ownermst)+ " + -1 + }", contentType:" , dataType:" , 成功:功能(响应){ alert(response.d.toString()); 清除(); __doPostBack(' <%= btnSch.UniqueID%>','); }, 错误:功能(xhr,状态,错误){ alert(xhr.responseText.toString()); } });
.ajax({ type: "POST", url: "WebService.aspx/fncOwnMstDml", data: "{ownermst:" + JSON.stringify(ownermst) + ",flag:" + -1 + "}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { alert(response.d.toString()); clear(); __doPostBack('<%= btnSch.UniqueID%>', ''); }, error: function (xhr, status, error) { alert(xhr.responseText.toString()); } });
我尝试过的事情:
我尝试将网址设为
What I have tried:
I have tried to put url like
url: "~/Master/WebService.aspx/fncOwnMstDml",</pre
Here Master is my folder name,fncOwnMstDml is my webmethod,WebService.aspx is .aspx page containing webmethod.I have even tried to put webservice.aspx outside of folder,and change url .
Please guide me.
Thanks in advance
如注释中所述,您不能使用在您的路径中〜,因为这是特定于.Net的.使用/代替,并且从客户端的角度来看,该URL必须在正在调用JS的页面中有效.
As mentioned in comments, you cannot use ~ in your path because that is specific to .Net. Use / instead and the url has to be valid from the page that is calling the JS from the client''s point of view.
这篇关于如何在调用json方法时提供文件夹路径位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文