Reputation: 435
Not too sure what happened here. I'm using Visual Studio 2010 .NET 4. With the following code, I WAS using JQuery 1.4.2 - with JQuery 1.4.2 the code worked just great. I'm calling a restful WCF RESTFUL method.
I created a simple Client with the following code:
Type = "POST";
Url = "http://localhost:60922/servicestart/SaveAllClients";
ContentType = "application/json; charset=utf-8";
DataType = "json"; ProcessData = true;
method = "SavePersons";
Data = JSON.stringify(formApplication);
CallService();
function CallService() {
$.ajax({
type: Type, //GET or POST or PUT or DELETE verb
url: Url, // Location of the service
data: Data, //Data sent to server
contentType: ContentType, // content type sent to server
dataType: DataType, //Expected data format from server
processdata: ProcessData, //True or False
success: function(msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
Now, the restful code in a separate project:
[WebInvoke(UriTemplate = "SaveAllClients", Method = "POST", ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
[OperationContract]
public string SavePersons(Person peeps)
{
string xml = string.Empty;
XMLToolset x = new XMLToolset();
xml = x.SerializeToXML(peeps);
xml = peeps.SerializeToXML(peeps);
// send xml to Oracle -
string json = string.Empty;
Person p = new Person();
p.first_name = "Good";
p.middle_name = "Happy";
p.last_name = "GH";
json = p.ConvertToJson(p);
return json;
}
Now using jquery 1.4.2 the code worked really well - basically it is a cross domain request. I decided to swap out jquery 1.4.2 to jquery 1.6.2 - for the sake of staying up to date - and well - it doesn't work now - it reports a service error O.
I studied the ajax documentation and the new features in jquery 1.5.2 and noticed a few things such as setting cross domain to true or using jsonp but neither of those worked.
Has something else changed in 1.6.2 from 1.4.2 in terms of how ajax functions?
Upvotes: 1
Views: 234
Reputation: 69915
May be you moved your service into a seperate project caused this issue.
Upvotes: 0
Reputation: 1039498
Your code is not working NOT because you switched from jQuery 1.4.2 to 1.6.2 but because you put your WCF service in a separate project. So I guess you hosted it in a separate application => you are now violating the same origin policy. And this policy has nothing to do with jQuery. It's a browser limitation.
So if you want to make this working you could configure your WCF service to use JSONP.
Upvotes: 3