Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a jquery ajax POST to a MVC Action (which returns action result). In that i retrive record from DB and store in Session and return partial view result . On my machine this works well, when deployed it in Windows Server 2008 R2 , A popup appears in the browser asking me to enter credentials (authentication required).

The jquery call:
---------------

Java
var data = $('#SearchForm').serialize();

           window.location.hash = '#/' + data;

           $.ajax({
               url: '/PromotionManagement/PromotionsSearch',
               type: 'POST',
               data: data,
               beforeSend: function (xhr) {
                   $('#search-result').hide();
                   $('#divresetCancel').hide();

                   $('#divwait').show();
                   // console.log('before sending request...');
               },
               error: function () {
                   //console.log("error processing request...");
               },
               success: function (data) {
                   debugger;
                   //console.log("successfully processed request...");
                   $('#search-result').html(data);
                   $('#search-result').show();

                   $('#divwait').hide();
                   $("#validation").html("");

                   if ($(data).html() == '\n        No Records Found \n    ') {
                       $('#divresetCancel').hide();
                   }
                   else {
                       $('#divresetCancel').show();
                   }


               }

           });

MVC Action :
------------


[HttpPost]
Java
public ActionResult PromotionsSearch(string list,string query)
    {
    
    //code to retrive the data from DB.
    
     Session["SearchPerameters"] = objSearchPerameters;
    
     return PartialView("PromotionsGrid", Promotions);
    
    }



I referred [this][1] link and stopped storing the data in Session.
Even though it didn't work .

Can you pls suggest me what is missing..

any help can be greatly appreciated.



[1]: http://stackoverflow.com/questions/16194828/jquery-ajax-call-fails-with-401-unauthorized[^]
Posted
Updated 4-Jan-14 11:46am
v3
Comments
Nelek 4-Jan-14 17:46pm    
Code blocks added and clickable link

Try is as below (use [AllowAnonymous] attribute).

SQL
[AllowAnonymous]
[HttpPost]
public ActionResult PromotionsSearch(string list,string query)
    {

    //code to retrive the data from DB.

     Session["SearchPerameters"] = objSearchPerameters;

     return PartialView("PromotionsGrid", Promotions);

    }
 
Share this answer
 
Comments
SrivaniS 5-Jan-14 11:20am    
Thank you for the reply Sampath..
This also doesn't work ..


and in Browser console , the response is shown below ..!

search button clicked..!! PromotionManagementIndex:1179
before sending request... PromotionManagementIndex:1282
Failed to load resource: the server responded with a status of 401 (Unauthorized) http://ausiwmslapp02.aus.amer.dell.com/PromotionManagement/PromotionsSearch
error processing request... PromotionManagementIndex:1285
Sampath Lokuge 6-Jan-14 2:54am    
Check this link may be helped to you.
http://forums.asp.net/t/984954.aspx?The+request+failed+with+HTTP+status+401+Unauthorized+
SrivaniS 6-Jan-14 4:22am    
Thank you Sampath really.. for your time !! :-)

This issue got fixed by changing the AJAX call url: '/PromotionManagement/PromotionsSearch' [controllerName/ActionName] as 'PromotionsSearch' [Only Action Name].
This issue got fixed by changing the AJAX call url: '/PromotionManagement/PromotionsSearch' [controllerName/ActionName] as 'PromotionsSearch' [Only Action Name].
 
Share this answer
 
v3

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