1
我的sendig JSON對象strid如下:如何發送JSON數據
var strid = "{id:'"+val.id+"'}";
$.ajax({
type: "POST",
url: "FrmUserPortal.aspx/AnnounceInfo",
data:JSON.stringify(strid),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var mydata = data.d;
alert(mydata);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
},
});
但將WebMethod並沒有叫。我的方法是
[WebMethod]
[ScriptMethod(UseHttpGet = false)]
public static Announce AnnounceInfo(string Id)
{
string dgFill = "Select AnnounceTitle,AnnounceDescription From AnnouncementInformation Where AnnouncetId = '"+Id+"'";
DataTable dtFill = DataManager.ExecuteQuery(dgFill);
Announce An = new Announce();
if (dtFill.Rows.Count > 0)
{
An.AnnounceTitle = dtFill.Rows[0]["AnnounceTitle"].ToString();
An.AnnounceDescription=dtFill.Rows[0]["AnnounceDescription"].ToString();
return An;
}
return An;
}
public class Announce
{
public string AnnounceTitle { get;set;}
public string AnnounceDescription { get; set; }
}
如果我沒有記錯......你不能在web服務中返回一個自定義類型......順便說一下,你的意思是不工作嗎?是否有任何錯誤或..? – User2012384 2014-09-23 09:07:36
你需要返回json結果 – Neel 2014-09-23 09:11:51
我建議你瀏覽你的路由配置 – Fka 2014-09-23 09:19:42