1

I'm trying to load a partialview from a JQuery load function enter image description here

The above basically calls a Load Action from Codes Controller enter image description here

This works when accessing the Web Application on an internal Network but not when it get access from the internet. Here are the steps I did on investigation:

  • Enable CORS on the IIS (web.config) and on the Code (AspNetCore.Cors)
  • Use JQUERY to enable CORS (using crossDomain:true)
  • Enable Network Discover on the Windows Server
  • I even tried putting the _Load.cshtml into the SHARED folder and calling the load directly without the path but still didn't work.

This question is linked to the question I posted but the CORS suggestion doesn't work.My Other Question

Aside from using the load, as mentioned, I have tried using $.ajax and output the error but I'm getting

readystate 0 status 0 statustext error ajax

Many thanks in advance.

------------------UPDATE----------------------

This is calling the URL directly as mentioned

enter image description here

------------------UPDATE 2----------------------

When calling from $.ajax, I put e.preventDefault();

enter image description here

Error showing in Chrome

enter image description here

Error Showing in IEenter image description here

tereško
  • 58,060
  • 25
  • 98
  • 150
  • Is your calling page (in which you have written jquery code for ajax) and the Action method URL (your baseURL variable) are in same domain? If both are in same domain then you do not need to worry about CORS. What happens when you directly visit that URL (baseURL + /Codes/Load?id=xxxxx) from your browser instead of ajax? does it give error? – Kiran Beladiya May 30 '17 at 09:17
  • @Kiran, yes, they are both in the same domain. When I run the url directly, I can see the correct result without css format. That works for both internal and external network. – Reydan Gatchalian May 30 '17 at 09:22
  • 1
    You do not need to use baseUrl at all since both are in same domain. You can use **.load("/Code/Load?id=.....");** directly. Also can you make sure #cmbGroup change event is not initiating postback (or redirect to other URL) right after the ajax call? – Kiran Beladiya May 30 '17 at 09:36
  • @Kiran, when I don't use the baseURL variable it doesn't work because of the Virtual Directory. – Reydan Gatchalian May 30 '17 at 09:40
  • Please share screenshot of dev toolbar when it is called from javascript – Kiran Beladiya May 30 '17 at 09:44
  • @Kiran, Updated with screenshots on Chrome and IE – Reydan Gatchalian May 30 '17 at 09:51
  • You may need to compare the difference in requests made by ajax and made directly in browser in fiddler. also there are similar error related questions I found here https://stackoverflow.com/questions/14527387/script7002-xmlhttprequest-network-error-0x2ef3-could-not-complete-the-operati and https://stackoverflow.com/questions/37868673/edge-on-windows-10-32-bit-blocking-ajax-call-to-localhost-with-network-error-0x2 and https://stackoverflow.com/questions/13176300/winjs-xhr-network-error-0x2efd-could-not-complete-the-operation-due-to-error-0 – Kiran Beladiya May 30 '17 at 10:01

1 Answers1

0

Thanks to Kiran for the help. I figured out the issue.

the URL from outside has port number in it. the problem is that when it calls the Control and the Action, the URL doesn't include the port number. The code now includes the port number but have to hard code it. I have tried using

@HttpContext.Current.Request.Url.Port

But it keeps on showing 80 rather than the actual port.

enter image description here