Home  >  Article  >  Web Front-end  >  A small detail about jquery ajax calling webservice with parameters to return XML data_jquery

A small detail about jquery ajax calling webservice with parameters to return XML data_jquery

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

Later, I found a post on an inconspicuous website, and someone’s suggestion reminded me.
My original code is written like this:
Error code

Copy code The code is as follows:

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

WS is written like this:
webservice
Copy code The code is as follows:

[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]
I found on the Internet that if it is a WS without parameters, there is nothing wrong with using the above data: "{}", but if there are parameters, it will be wrong.
In fact. It's very simple, just make a few small modifications
Correct code
[code]
$.ajax({
type: "post",
url: "_service. asmx/getDataFromATable",
data: { tablename: temp },
dataType: "XML",
...

This is an insignificant little detail.
What I want to say is that some people, whether they are experts or novices, should not blindly repost other people's things.
Please repost something correct.
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