Jquery Rest communication with WCF 3.5

I'm testing the basics for exchanging rest messages between a asp.net mvc site and a WCF 3.5 service. The service is built using the template found in the WCF REST Starter Kit found on codeplex. I would like to exchange json messages using jquery. The REST Singleton service is working properly and it also provide examples of all the possible calling adding the help parameter ad the end of the uri. I arrive to perform GET requests with the built in jquery $.getJSON. I have problems doing the PUT (for updating values) and POST.

$.ajax({
     type: "PUT",
     dataType: "json",
     url: "http://localhost:1045/Service.svc/?format=json",
     data: '{"Value":testvalue}'
 });

What is the best approach for this? Is it possible not to use Ms. Ajax at all and is it correct to bypass it?

Answers


"PUT" and "DELETE" are not supported by all browsers according to jQuery

The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.

http://docs.jquery.com/Ajax/jQuery.ajax#options

I didn't really understand your question though. Are you having a problem doing a PUT and a POST or just a POST? Does the GET work fine?

One error that I noticed was your data, notice I added it without quotes.

$.ajax({
     type: "PUT",
     dataType: "json",
     url: "http://localhost:1045/Service.svc/?format=json",
     data: { Value: "testvalue" }
});

Also make sure you have your contentType set correctly in your ajax call.

contentType: "application/json"

The JQuery default is

contentType: "application/x-www-form-urlencoded"


Need Your Help

String.contains(searchText) doesn't work for more than one word

java android regex pattern-matching string-matching

I have some content and I am trying to find if the some "searchText" exists in the content. When I look for a single word in the "searchText", the String.contains(searchText) returns true but returns

iPhone - Detect (recognize) a visual pattern or object using the device's camera

iphone camera pattern-recognition

I would like to develop a simple application to detect (recognize) a certain pattern (lets say the logo of a car manufacturer) using the iPhone's camera.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.