Monday, 2 September 2013

Using MVC 4 as Web Service

Using MVC 4 as Web Service

I'm now trying to build a web service based on MVC 4 and client using
HTML. The problem is my HTML file is put outside the application:
Here is my code of Index method inside my Controller:
public ActionResult Index() {
return Content("It works");
}
And this is my code in client side:
$.ajax({
url: 'http://localhost:54502/<MyControllerName>/Index',
type: 'POST',
datatype:"JSON",
contentType:"application/json; charset=utf-8",
success: function(data) {
alert(data);
},
error: function(data) {
alert("error");
},
complete: function(jqXHR,status) {
}
});
The problem is it always alert out "error" and nothing seems to work. Any
help would be highly appriciated!

No comments:

Post a Comment