Later, I found a post on an inconspicuous website, and someone’s suggestion reminded me.
My original code is written like this:
Error code
$.ajax({
type: "post",
url: "_service.asmx/getDataFromATable",
data: " { tablename: temp }",
dataType: "XML"
...
WS is written like this:
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]
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.