Extjs ajax 写后台程序用asmx文件,以次是代码?出错时找不到正确的Url
Extjs ajax 写后台程序用asmx文件,以下是代码?出错时找不到正确的Url
前台Js:
<script type="text/javascript">
Ext.onReady(function () {
var button = new Ext.Button({
renderTo: "div1",
text: "后台Ajax提交",
handler: function () {
Ext.Ajax.request({
url: 'WebService1.asmx/HelloWorld',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
// headers: {
// 'userHeader': 'userMsg'
// },
params: { a: 10, b: 20 },
method: 'GET',
success: function (response, options) {
Ext.MessageBox.alert('成功', '从服务端获取结果: ' + response.responseText);
},
failure: function (response, options) {
Ext.MessageBox.alert('失败', '请求超时或网络故障,错误编号:' + response.status);
}
});
},
id: "bt1"
});
});
</script>
后台asmx: public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}

请高手指教啊
------解决方案--------------------
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
把第四行的注释去掉就行了,20分给我吧
前台Js:
<script type="text/javascript">
Ext.onReady(function () {
var button = new Ext.Button({
renderTo: "div1",
text: "后台Ajax提交",
handler: function () {
Ext.Ajax.request({
url: 'WebService1.asmx/HelloWorld',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
// headers: {
// 'userHeader': 'userMsg'
// },
params: { a: 10, b: 20 },
method: 'GET',
success: function (response, options) {
Ext.MessageBox.alert('成功', '从服务端获取结果: ' + response.responseText);
},
failure: function (response, options) {
Ext.MessageBox.alert('失败', '请求超时或网络故障,错误编号:' + response.status);
}
});
},
id: "bt1"
});
});
</script>
后台asmx: public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
请高手指教啊
------解决方案--------------------
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
把第四行的注释去掉就行了,20分给我吧