Later, I found a post on an inconspicuous website, and a suggestion from someone reminded me.
My original code is written as follows:
Error Code
Copy codeThe Code is as follows: $. ajax ({
Type: "post ",
Url: "_ service. asmx/getDataFromATable ",
Data: "{tablename: temp }",
DataType: "XML"
...
WS is written as follows:
WebserviceCopy codeThe 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]
If ws without parameters are found on the Internet, there is no error in using the above data: "{}", but the passing of parameters will fail.
It's actually very easy. You only need to make a small modification.
Correct code
[Code]
$. Ajax ({
Type: "post ",
Url: "_ service. asmx/getDataFromATable ",
Data: {tablename: temp },
DataType: "XML ",
...
This is a trivial little detail.
I would like to say that some people, whether it's a cool man or a newbie, should not blindly repost others' things.
Please repost some correct ones.