A small detail about XML data returned by jquery ajax calling webservice with Parameters

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.