Reputation: 3226
What is a 302 found error code in asp.net mvc3 ? I am trying to do a simple jquery $.get call to get current time stamp from the server.
following is the code :
javascript
var url = '/Utility/GetTimeStamp';
$.get(url, function(data){ $("#curr_time").val(data); });
c# mvc
public ActionResult GetTimeStamp()
{
string time_stamp = DateTime.Now.ToString("o");
return Content(time_stamp);
}
Upvotes: 2
Views: 1266
Reputation: 21038
Do you have anything like this in your web.config?
<location path="assets">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="scripts">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
I was having this issue and for all un-authenticated requests were being re-directed to the sign in page. try pasting the ajax url in a new browser window and see what you get.
Upvotes: 0
Reputation: 930
you mean 304?
1、add a random number or datatime to you ajax request($.get) param
2、use $.ajax({cache:false})
3、set no cache in server side code like
HttpContext.Response.Cache.SetNoStore();
Upvotes: 0
Reputation: 1082
if the name of the contoller is UTILITY.. and currently you are there
try this code
javascript
var url = 'GetTimeStamp';
$.post(url
,{}
, function(data)
{
$("#curr_time").val(data);
});
C# MVC
[HttpPost]
public JsonResult GetTimeStamp()
{
string time_stamp = DateTime.Now.ToString("o");
return Json(time_stamp);
}
its returning a json result.
Upvotes: 1