question

AppDev-1530 avatar image
0 Votes"
AppDev-1530 asked AgaveJoe edited

MVC javascript $.post not working on server But works in Localhost

Hi All,

I have this line in Index.cshtml

         $.post("../Write/Index", { TypeFilter: TypeID, StatusFilter: StatusID }, function (data) { $("#FilteredQueue").html(data); });

I use this this to help filter and data that is in the index page



This the error that shows that in the F12
jquery-3.3.1.js:9600 POST http://apps/Write/Index 503 (Service Unavailable)

This error only shows up when running on the server
On localhost it work.


In the controller:


     [HttpPost] //See This Error https://stackoverflow.com/questions/33377232/jquery-post-works-locally-but-not-on-server
                //public ActionResult FilteredQueue(int? TypeFilter, int? StatusFilter)
     public ActionResult Index(int? TypeFilter, int? StatusFilter)
     {

         if (((StatusFilter == 2) || (StatusFilter == 6) || (StatusFilter == 5) || (StatusFilter == 8)) && (TypeFilter == null)) //Closed Request Exception  no Status Type Filter Return Everything that was parked Close and Colsed Completed
         {
             var FilteredList = db.WRITE_REQ_REQUEST_TBL.Where(Request => Request.REQ_REQUEST_STATUS_ID == StatusFilter).OrderBy(R => R.REQ_REQUEST_DATE).ToList();
             ViewBag.FilteredResults = FilteredList;

             TypeFilter = null;
             StatusFilter = null;

             return PartialView("~/Views/Write/_FilteredQueue.cshtml", ViewBag.FilteredResults);
         }
         else if (((StatusFilter == 2) || (StatusFilter == 6) || (StatusFilter == 5) || (StatusFilter == 8)) && (TypeFilter != null)) //Closed Request Exception  no Status Type Filter Return Everything that was parked Close and Colsed Completed
         {
             var FilteredList = db.WRITE_REQ_REQUEST_TBL.Where(Request => Request.REQ_REQUEST_STATUS_ID == StatusFilter && Request.REQ_REQUEST_TYPE_ID == TypeFilter).OrderBy(R => R.REQ_REQUEST_DATE).ToList();
             ViewBag.FilteredResults = FilteredList;

             TypeFilter = null;
             StatusFilter = null;

             return PartialView("~/Views/Write/_FilteredQueue.cshtml", ViewBag.FilteredResults);
         }
         else
         {

             if (TypeFilter != null && StatusFilter != null)
             {
                 var FilteredList = db.WRITE_REQ_REQUEST_TBL.Where(Request => Request.REQ_REQUEST_STATUS_ID == StatusFilter && Request.REQ_REQUEST_TYPE_ID == TypeFilter && Request.REQ_REQUEST_STATUS != true && Request.REQ_REQUEST_STATUS != false).OrderBy(R => R.REQ_REQUEST_DATE).ToList();

                 TypeFilter = null;
                 StatusFilter = null;

                 ViewBag.FilteredResults = FilteredList;
             }

             else if (TypeFilter != null && StatusFilter == null)
             {
                 var FilteredList = db.WRITE_REQ_REQUEST_TBL.Where(Request => Request.REQ_REQUEST_TYPE_ID == TypeFilter && Request.REQ_REQUEST_STATUS != true && Request.REQ_REQUEST_STATUS != false).OrderBy(R => R.REQ_REQUEST_DATE).ToList();

                 TypeFilter = null;
                 StatusFilter = null;

                 ViewBag.FilteredResults = FilteredList;

             }

             else if (TypeFilter == null && StatusFilter != null)
             {
                 var FilteredList = db.WRITE_REQ_REQUEST_TBL.Where(Request => Request.REQ_REQUEST_STATUS_ID == StatusFilter && Request.REQ_REQUEST_STATUS != true && Request.REQ_REQUEST_STATUS != false).OrderBy(R => R.REQ_REQUEST_DATE).ToList();

                 TypeFilter = null;
                 StatusFilter = null;

                 ViewBag.FilteredResults = FilteredList;
             }


             //return View(ViewBag.FilteredResults);
             else if (TypeFilter == null && StatusFilter == null)
             {
                 var FilteredList = db.WRITE_REQ_REQUEST_TBL.Where(Request => Request.REQ_REQUEST_STATUS_ID != 2 && Request.REQ_REQUEST_STATUS_ID != 5 && Request.REQ_REQUEST_STATUS_ID != 6 && Request.REQ_REQUEST_STATUS_ID != 8 && Request.REQ_REQUEST_STATUS != true && Request.REQ_REQUEST_STATUS != false).OrderBy(R => R.REQ_REQUEST_DATE).ToList();
                 /* && (Request.REQ_REQUEST_CLOSE_DATE - DateTime.Today).Value.TotalDays > 10).ToList();*/

                 TypeFilter = null;
                 StatusFilter = null;

                 ViewBag.FilteredResults = FilteredList;

             }
             else
             {
                 var FilteredList = db.WRITE_REQ_REQUEST_TBL.Where(Request => Request.REQ_REQUEST_STATUS_ID != 2 || Request.REQ_REQUEST_STATUS_ID != 5 || Request.REQ_REQUEST_STATUS_ID != 6 || Request.REQ_REQUEST_STATUS_ID != 8 && Request.REQ_REQUEST_STATUS != true && Request.REQ_REQUEST_STATUS != false).ToList();

                 TypeFilter = null;
                 StatusFilter = null;

                 ViewBag.FilteredResults = FilteredList;

             }

             return PartialView("~/Views/Write/_FilteredQueue.cshtml", ViewBag.FilteredResults);
         }
     }

dotnet-csharpdotnet-aspnet-generaldotnet-aspnet-mvc
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered AppDev-1530 commented

check the url in the network trace. its probably invalid

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you!

I am still learning this new site and how it works.
Thanks for the network trace thing.

For some reason I guess my code was working but the trace thing confirmed it.

Thanks again!

0 Votes 0 ·
AppDev-1530 avatar image
0 Votes"
AppDev-1530 answered AppDev-1530 edited

Hi Bruce,

Wow would I do that?

I am not sure what you mean by network trace sorry.

Edit: I found it :
Capturing the network trace file on Google Chrome
From the Chrome menu bar, select View > Developer > Developer Tools. From the panel that opens, select the Network tab. Look for a round record button in the upper-left corner of the tab, and make sure it is red. If it is grey, click it once to start recording.Apr 21, 2020


And will it be obvious it is invalid?

I guess it would show up red. For some reason it's working now... maybe the new published pages had not loaded.
as all seems well.


Would be be the method of correcting this?
What would a valid url look like for this?

It is just so odd. Thanks

Update All is working
THanks for the tip on the netwrok trace thing!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AgaveJoe avatar image
0 Votes"
AgaveJoe answered AppDev-6938 commented

Try a relative reference from the application root.

$.post("/Write/Index", { TypeFilter: TypeID, StatusFilter: StatusID }, function (data) { $("#FilteredQueue").html(data); });


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ahh this is how you reply still learning the site.

Thanks as I stated above some reason it is working now.
I am guessing my published changes are working now.
My guess is that the browser was using an old page.

So is there something out there that explains this like of code better?
I mean I know it is calling my controller and passing in the values of the form
to the controller as parameters but is this ajax or is this just javascripts?

I am not 100% sure where I found this solution but it seems to work now.
But I would like to better understand which language this is from.

0 Votes 0 ·

It is jQuery which is a JavaScript library.

0 Votes 0 ·

This did not work. Do you have any other ideas?
It is so odd that it works from localhost


I had $.post("../Write/Index", { TypeFilter: TypeID, StatusFilter: StatusID }, function (data) { $("#FilteredQueue").html(data); });

And I changed it to this : $.post("/Write/Index", { TypeFilter: TypeID, StatusFilter: StatusID }, function (data) { $("#FilteredQueue").html(data); });


When I had the 2 dots before the url it works sometimes ... without the 2 dots it does not work at all.
It is so odd.

Error without the 2 dots
240238-image.png


With the 20 dots this is the error
240262-image.png


0 Votes 0 ·
image.png (87.9 KiB)
image.png (87.5 KiB)
AgaveJoe avatar image
0 Votes"
AgaveJoe answered AgaveJoe edited

The slash means "from the application root". Using the slash was just a guess as we cannot see your application's directory structure or MVC routes.

When I had the 2 dots before the url it works sometimes ... without the 2 dots it does not work at all.

The .. means up one directory level from the current directory. It makes sense that the .. works on some pages but not others.

The 503 indicates the URL is pointing to a nonexistent web application. Most likely the IIS application is not configured correctly because both the slash and the .. cause a 503 error. I would expect the slash to either work or cause in a 404 (Not Found). Also, the URL http://apps/Write/Index is rather odd. In a production app I'd expect a domain name, computer name, or IP address not "apps" on the production system.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.