About jquery Ajax call with parameters WebService returns XML data a small detail _jquery

Source: Internet
Author: User
Later in a humble station to find a post, a person's a suggestion to remind me.
My original code was written like this:
Error code
Copy Code code as follows:

$.ajax ({
Type: "Post",
URL: "_service.asmx/getdatafromatable",
Data: "{tablename:temp}",
DataType: "XML"
...

WS is written in this way:
WebService
Copy Code code 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]
Online search, all said that if the WS without parameters, with the above data: "{}" is not wrong, but there are parameters such a pass will be an error.
It's simple, it's just a little bit of a change to make.
Correct code
[Code]
$.ajax ({
Type: "Post",
URL: "_service.asmx/getdatafromatable",
Data: {tablename:temp},
DataType: "XML",
...

This is a trivial little detail.
What I want to say is that some people, whether they are cattle or novice, do not blindly reprint other people's things.
Please reprint some of the correct.

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.