Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I created a mvc3 application.in which the below method inside HomeController.cs.

public JsonResult StringReturn()
{
string s="hai";
return Json(s);
}


then calling the above method from views/Home/Index.cshtml using

jquery as below

function GetString() {

$.ajax({

type: "POST",
url: "Home/StringReturn",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: '{}',
error: function (jqXhr, textStatus, errorThrown) {
alert("Error '" + jqXhr.status + "' (textStatus: '" + textStatus + "', errorThrown: '" + errorThrown + "')");
},
success: function (result, textStatus) {

alert(result);
}
});

}


it work when i run it from visual studio.but getting error message 'Error 405(textStatus:'error',errorThrown:'undefined')'

when i browse it from hosted iis.how to resolve this?



thanks..
Posted
Updated 12-Aug-13 21:51pm
v2

1 solution

Try using the following piece of code.

C#
[HttpPost]
public JsonResult StringReturn()
{
    string s="hai";
    return Json(s);
}
 
Share this answer
 
Comments
hasbina 13-Aug-13 4:29am    
@Das
no.getting same error
Deviprasad Das 13-Aug-13 5:13am    
Hi Hasbina

Since you are getting 4XX error code, it resembles a client side error.
there is some problem with your client side code.

Have you tried seeing the request/response in fiddler/firebug?

Thanks
Deviprasad
hasbina 13-Aug-13 5:21am    
can you explain...
Thanks..
Deviprasad Das 13-Aug-13 5:34am    
Fiddler is a tool, by using which you can see the request data and header information that is passed to the server.

Using it you can check if you have missed anything.
hasbina 13-Aug-13 6:00am    
@das

my doubt is may be the error in getting url..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900