Home  >  Article  >  Web Front-end  >  关于jquery ajax 调用带参数的webservice返回XML数据一个小细节_jquery

关于jquery ajax 调用带参数的webservice返回XML数据一个小细节_jquery

WBOY
WBOYOriginal
2016-05-16 17:51:151026browse

后来在一个不起眼的小站找到一个帖子,某个人的一个建议提醒了我。
我原来的代码是这样写的:
错误代码

复制代码 代码如下:

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

WS是这样写的:
webservice
复制代码 代码如下:

[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]
网上搜到的,都说如果是无参数的WS,用上面的data:"{}"是没有错的,但有参的这样传会出错。
其实很简单,只需要做一点小小的修改就可以了
正确代码
[code]
$.ajax({
type: "post",
url: "_service.asmx/getDataFromATable",
data: { tablename: temp },
dataType: "XML",
...

这是一个微不足道的小细节。
我想说的是,某些人,无论是牛人还是新手,不要盲目地转载别人的东西。
请转载一些正确的。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn