Use Jquery Aajx to access the WCF Service (GET, POST, PUT, DELETE)

Source: Internet
Author: User

Copy codeThe Code is as follows: using jquery ajax call wcf service get/post/put/delete
Http://www.codeproject.com/Articles/254714/Implement-CRUD-operations-using-RESTful-WCF-Servic
Using POST Method
Retrieve a representation of the addressed member of the collection, in the example below, create a new entry in the collection.
Collapse | Copy Code
$. Ajax ({
Type: "POST ",
Url: "Services/EFService. svc/Members /",
Data: "{Email: 'test @ test.com ', ScreenName: 'testuser '}",
ContentType: "application/json; charset = UTF-8 ",
DataType: "json ",
Success: function (data) {// Play with response returned in JSON format },
Error: function (msg ){
Alert (msg );
}
}); Using PUT Method
Update the entire collection with another collection, in the example below, update the addressed member of the collection.
Collapse | Copy Code
$. Ajax ({
Type: "PUT ",
Url: "Services/EFService. svc/Members /",
Data: "{Email: 'test @ test.com ', ScreenName: 'testuser '}",
ContentType: "application/json; charset = UTF-8 ",
DataType: "json ",
Success: function (data) {// Play with response returned in JSON format },
Error: function (msg ){
Alert (msg );
}
}); Using DELETE Method
Delete the entire collection or a specific collection, in the example below, delete Member with id = 1.
Collapse | Copy Code
$. Ajax ({
Type: "DELETE ",
Url: "Services/EFService. svc/Members (1 )",
Data :"{}",
ContentType: "application/json; charset = UTF-8 ",
DataType: "json ",
Success: function (data) {// Play with response returned in JSON format },
Error: function (msg ){
Alert (msg );
}
});

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.