亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

關(guān)于jquery ajax 調(diào)用帶參數(shù)的webservice返回XML數(shù)據(jù)一個小細節(jié)

 更新時間:2012年07月31日 23:43:58   作者:  
很早之前用jquery調(diào)用帶參數(shù)的WS返回XML格式數(shù)據(jù)的時候,傳參的時候會出現(xiàn)錯誤。問了問度娘和谷哥,這娘兒倆一個德行,里面的多數(shù)帖子沒什么意義,你粘我,我復(fù)制你
后來在一個不起眼的小站找到一個帖子,某個人的一個建議提醒了我。
我原來的代碼是這樣寫的:
錯誤代碼
復(fù)制代碼 代碼如下:

$.ajax({
type: "post",
url: "_service.asmx/getDataFromATable",
data:" { tablename: temp }",
dataType: "XML"
...

WS是這樣寫的:
webservice
復(fù)制代碼 代碼如下:

[WebMethod]
public DataSet getDataFromATable(string tablename)
{
DataSet ds = new DataSet();
using (SqlConnection con=new SqlConnection(connectionString))
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = string.Format("select * from {0}",tablename);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
return ds;
}
[code]
網(wǎng)上搜到的,都說如果是無參數(shù)的WS,用上面的data:"{}"是沒有錯的,但有參的這樣傳會出錯。
其實很簡單,只需要做一點小小的修改就可以了
正確代碼
[code]
$.ajax({
type: "post",
url: "_service.asmx/getDataFromATable",
data: { tablename: temp },
dataType: "XML",
...

這是一個微不足道的小細節(jié)。
我想說的是,某些人,無論是牛人還是新手,不要盲目地轉(zhuǎn)載別人的東西。
請轉(zhuǎn)載一些正確的。

相關(guān)文章

最新評論