jQuery Ajax url问题 [英] jQuery Ajax url problem
问题描述
我试图使用jQuery ajax从asp.net中的Master Page访问webmethod。名为Module的文件夹包含母版页。所有其他子页面都位于Module文件夹下的子文件夹下。我在maste页面写了一个ajax post代码,如下所示
var GetNotification = function() {
$ .ajax({
type:' POST',
url:' MyTest.Master / Test',
async : false ,
cache: true ,
dataType:' json',
contentType:' application / json; charset = utf-8',
data:' {}',
success:function(data){
alert(data.d);
},
错误:函数(请求,状态,错误){
alert(request.responseText);
}
});
}
如果我进入主页,其路径将在Modules / Home上。但我的网络方法是在'Modules / MyTest.Master / Test'上。我无法导航到webmethod的正确网址。你能帮我吗?
.ajax({
type:' POST',
url:' MyTest.Master /测试',
async : false ,
cache:< span class =code-keyword> true ,
dataType:' json',
contentType:' application / json; charset = utf-8',
数据:' {}',
成功:函数(数据){
alert(data.d);
},
错误:函数(请求,状态,错误){
警报(request.responseText);
}
});
}
如果我进入主页,其路径将在Modules / Home上。但我的网络方法是在'Modules / MyTest.Master / Test'上。我无法导航到webmethod的正确网址。能帮助我吗。
请在aspx.cs页面中写下该webmethod并将网址提供为'somefolder / youraspxpage.aspx / yourmethodname'
< blockquote>
尝试将你的方法放在page.aspx中,而不是在主模板中
url:' MyTest.aspx / Test',
因为url没有检测到MyTest.Master。我的意思是.master扩展
Hi,
I've tried to access a webmethod from a Master Page in asp.net using jQuery ajax. A folder named 'Module' holds the master page. All the other child pages reside under the subfolder on the 'Module' folder. I've written an ajax post code in the maste page like below
var GetNotification = function () {
$.ajax({
type: 'POST',
url: 'MyTest.Master/Test',
async: false,
cache: true,
dataType: 'json',
contentType: 'application/json;charset=utf-8',
data: '{}',
success: function (data) {
alert(data.d);
},
error: function (request, status, error) {
alert(request.responseText);
}
});
}
if I enter into the Home page its path will be on Modules/Home. But my webmethod is on the 'Modules/MyTest.Master/Test'. I cant navigate to the webmethod's correct url. Can you please help me.
.ajax({ type: 'POST', url: 'MyTest.Master/Test', async: false, cache: true, dataType: 'json', contentType: 'application/json;charset=utf-8', data: '{}', success: function (data) { alert(data.d); }, error: function (request, status, error) { alert(request.responseText); } }); }
if I enter into the Home page its path will be on Modules/Home. But my webmethod is on the 'Modules/MyTest.Master/Test'. I cant navigate to the webmethod's correct url. Can you please help me.
Please wrote that webmethod in a aspx.cs page and provide the url as 'somefolder/youraspxpage.aspx/yourmethodname'
Hi,
try to put your method in a page.aspx not in the master templage
url: 'MyTest.aspx/Test',
Because url does not detect MyTest.Master . I mean .master extention
这篇关于jQuery Ajax url问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!