Web服务方法不起作用 [英] Webservice method not working
本文介绍了Web服务方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在App-Code文件夹中有一个web服务Default.asmx代码。Default.cs按下按钮我想显示来自webservice的Webmethod字符串。但是没有工作。如何为app_code webservice文件输入url ?
我尝试了什么:
webservice
I have a webservice"Default.asmx" code behind file in App-Code folder."Default.cs" While button click i want to display Webmethod string from webservice.But not working.How o type url for app_code webservice file?
What I have tried:
webservice
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
//[ScriptService]
public class _Default : System.Web.Services.WebService {
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
SqlConnection conRecipes = new SqlConnection(ConfigurationManager.ConnectionStrings["constrRecipes"].ConnectionString);
public _Default () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string AddNominations()
{
return "Nomination Added Successfully";
}
Ajax调用
Ajax call
function CallService() {
$.ajax({
type: "POST",
url: "_Default.asmx/AddNominations",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: Success,
error: Error
});
}
function Success(data, status) {
$("#lblResult").removeClass("loading");
$("#lblResult").html(data.d);
}
function Error(request, status, error) {
$("#lblResult").removeClass("loading");
$("#lblResult").html(request.statusText);
}
推荐答案
.ajax({
type: POST,
url: _ Default.asmx / AddNominations,
data: {} ,
contentType: application / json; charset = utf-8,
dataType: json,
成功:成功,
错误:错误
});
}
函数成功(数据,状态){
.ajax({ type: "POST", url: "_Default.asmx/AddNominations", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: Success, error: Error }); } function Success(data, status) {
( #lblResult)。removeClass( loading);
("#lblResult").removeClass("loading");
( #lblResult)。html(data.d) ;
}
函数错误(请求,状态,错误){
("#lblResult").html(data.d); } function Error(request, status, error) {
这篇关于Web服务方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文