Relative url issue with an Ajax call on IE9 - javascript

I am working on an ASP.Net MVC 5 application that has lot of ajax calls using jquery post as well as Kendo UI DataSource. I have a problem previously with relative urls which are working when I run the project from VisualStudio under IIS Express where the URL does not have site name (ex. http://localhost:22332/ ) and It stopped working once I deployed this to test because of site name in the url (http://orgname.com/SiteName/).
I have resolved this by setting "base" in my _Layout.cshtml page like this.
<base href="~/" />
Everything was fine until I ran into issue with one ajax call on IE9.
My Ajax call is like this:
$.post("Controller/Method")
when I am on the page http://localhost:36380/Controller/New, the above jquery post is submitted to http://localhost:36380/Controller/Method in Chrome, IE10 and IE 11, which is what is expected.
But in IE 9 it is being submitted to http://localhost:36380/Controller/New/Controller/Method
value of base is same in all the browsers which is "/" for localhost.
Is there a different behavior that I need to handle for IE9? This post is in a js file. If I can use ASP.Net MVC helper from a js file that can solve my problem too. Any suggestions?

Related

Why do I have differences with AJAX hosted local vs remote?

I guess part of my answer relates to "same-origin" but I'm not still not absolutely clear on when it applies and when not (or why it works in one instance, but is not a solution in other cases).
I am using latest jQuery, jQuery mobile and Apache/MySQL/PHP stacks. Client is either Windows 7/Firefox 38, or iPad/PhoneGap.
My AWS hosted php code serves the following to help resolve "same origin":
$http_origin = $_SERVER['HTTP_ORIGIN'];
header("Access-Control-Allow-Origin: $http_origin");
The Phone Gap version of my app works as expected, retrieving data from my AWS server and rendering the data it has retrieved.
Calling the exact same code from my laptop browser fails. Why?
If I copy/paste the AJAX URL into my browser, it correctly pulls the JSON data from AWS.
In an effort to resolve, I dump output to console.log. The jQuery AJAX "error" section gets called instead of the "success" portion. The same "error" result occurs if I call the index.html file (which calls JS) using File Open within Firefox, or if I call the locally apache hosted index.html file, jQuery ajax jumps to "error" section.
So if my phonegap app works, but my laptop does not, why? I mean, I see my app being akin to the laptop web browser. They both in effect have a different origin than my web server so I would expect either both work, or both fail.
If someone can help clarify it would be great - I have twice spent time chasing a problem that only exists in my dev environment but works just fine in production - its frustrating!
Thanks all in advance
Have you white listed domain in your phonegap config ?
http://docs.phonegap.com/en/4.0.0/guide_appdev_whitelist_index.md.html
ex:
Access to google.com:
<access origin="http://google.com" />
__ reading it should improve : https://github.com/phonegap/phonegap-app-developer/issues/169 __

First ajax request not succeeding in Chrome, working in other browsers

Here is what i am doing.
I have a webpage(with SSL). Call it s1.
It hosts a .js file, which installs a 3rd-party js, used to navigate it. (say s2)
On a click on an element, it loads an iframe(another website, say s2), which in turn passes data to my js hosted on s1.
This is working correctly in IE, Firefox etc, but in Chrome, the first such instance gets cancelled.
When i try again (after the first request is cancelled), it works as expected. (after the first cancellation).
Any ideas on what might be happening. Am not sure how to post a working snippet here as the second iframe is a protected one.
I am guessing something to do with Cross-domain communication, but not sure as it's working in other browsers.
Any ideas on what could be happening.
Thanks

Symfony2 Web Profiler disappeared ajax calling but invalid response in google chrome only

Im just working on a project with symfony2 and yesterday i started to design it.
Not i just noticed that the web profiler is not visible.
I tried everything! it is active in the config_dev, body tags are opened and closed well. The JS Code is loaded just before </body> and the /_wdt request is called, but heres the response:
now just calling myself this url returns the right response. in this case, the toolbar is shown.
I just tried the same with safari and firefox and everything worked well?! So only it is failing with chrome (even in ikognito mode with no plugin).
so it must have something to do with what? i dunno..
and since this time TinymceBundle not works well also. Even if the js code is loaded my textarea with the .tinymce class is not a Tinymce Textarea, Some Js code errors?
Thanks!
I am using Zend Server CE as Environment. Just stopping and Starting the Server fixed the bug?!

When accessing site from external network using IE JS/CSS(YUI) based UI is not working correctly

We have ASP.NET application in which we have used the YUI to generated the popup for user interface. Now when I amd testing the locally isntalled site the popups are comming correctctly withoug any error and also getting displayed correctly on all the browwsers (including IE 7/8/9).
However when the site is exposed on the server and i tried to test it from the outside network the YUI popup's are not getting genrated correclty like if some Javascript or CSS are not getting loaded or are cached. Generally Ctr+F5 does the trick to flush local cache and to fix the issue we have added query parameters xyz.css?v=10 trick. But its not working. Now this issue is showing only on the IE(6/7/8/9) and other browsers are working correctly. To check the issue i again logged into the production box and found that popup is appearing correctly on IE also.
Now i am not having clue how it could possibly happen. Does any one has came across anything like this? What could be the cause of the issue and how to fix it ?
Thanks
As far as I know, IE caches GET responses.
The xyz.css?v=10 trick is used when you want it to use cached CSS but only as long as it is the same version. Whenever you change something in the css you need to change the url (ie xyz.css?v=20).
If you want IE to NEVER use the cached css, you need the URL to look different everytime. you can do that by adding some timestamp to the url.
something like:
xyz.css?v=201201180600123
(201201180600123 is a timestamp)

Page reloades in Firefox when using anchor?

Hi,
I have a ASP.NET MVC application that runs Microsoft Ajax and jQquery. If I run the following url in firefox :
http://localhost:16055/Ad/Detail/13#contactMail
The page will reload itself again and again? If I run the same url in Explorer or Chrome nothing will happen (the correct behavior)?
When removing this script includes the reload will stop in Firefox :
<script type="text/javascript" src="../../../Scripts/MicrosoftAjax.js"></script>
Then I will just get a error (not found) in MicrosoftMvcValidation.js.
This is true for all pages, even for the ones without editors.
Any idea?
Looks like you might have a version of MicrosoftAjax.js with a bug - sounds like exactly the same problem as this person had. You can get the latest version here.

Categories

Resources