I want to call AJAX Request from one subdomain to other.
Say I want to request http://subdomain2.site.com/ajax/handler.ashx from a ASPX page on other subdomain http://subdomain1.site.com/Default.aspx
Any IDEA how to do this?
According to https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript, you can set document.domain to a suffix of the domain, so
document.domain='example.com'
However, I have not tested this.
have you taken a look at JSONP?
Related
Hi Folks,
my first post here, thanks for any help i got already throught reading before.
I am working on a wordpress projekt. And it seems i am missing the overview on my problem.
I use ajax to recieve additional product data. http:url/product/additional_ajax_data...
This works fine, except direct call of the ajax urls. Direct call of a ajax url gives
a 404 not found.
Please dont give instructions like: add 200 ok to header... Cause the project will
consist of some thousand pages and work arounds like this are a no go...
Aditional infos: the urls have no ajax hash tag... And the content will dynamicly loaded depending on last url fragment
I found the solution:
To prevent Wordpress of 404 when calling a ajax url directly, add rewrite endpoints to the system.
You can follow the post from Jon Cave on Wordpress:
http://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/
Works also on custom post_types and custom taxonomys, keep an eye on the type for wich you want to register a custom endpoint rewrite (that may depends on your options from your post type, page type etc...).
If you are sure that url is correct and file is there, check if permissions on file are not too strict. Also check .htaccess to make sure it doesn't black certain file extensions to be loaded directly
I have an AJAX call to a server endpoint that does a 301 redirect to the same page, but with a trailing slash.
Does the browser follow redirects when called with AJAX or does it ignore them? In my case it doesn't follow them, but I figured it might be something from the server config.
If you are using jquery you could look at the questions below to implement it. By default jQuery (and most libraries with Ajax) don't follow redirects by default:
How to manage a redirect request after a jQuery Ajax call
How to prevent ajax requests to follow redirects using jQuery
handle jquery ajax redirect
Maybe this answer is a little bit late but i had the same problem with 301 response on ajax request. The solution was quite simple:
apache rewrite rule is something like this:
RewriteRule ^([^/]\w+)/?$ index.php?%{QUERY_STRING} [L,E=MODULE:$1]
Your XHR-Request url looks someting like this:
/this/is/a/canonical/url + '?param=1¶m=2...'
It will lead to the 301 moved permanently if you dont use a direct file call (f.i. *.php) and rewrite to canonical URL (looks like a directory-path without f.i. *.php) instead.
To solve this problem just add a / to your XHR-Request-URL like this:
/this/is/a/canonical/url + '/' + '?param=1¶m=2...'
Maybe this will help someone.
I also had this problem and the suggestion about the trailing slash got me thinking ... I had a rewrite rule in my Web.Config to make everything lowercase and that's what was messing up my AJAX call. I was POSTing to GetResults (which showed up as a 301) and my rewriter (for some unknown reason?) was changing it to a lower-cased getresults GET which resulted in a 404.
Hope this might help someone else.
According to jQuery's API doc (http://api.jquery.com/jQuery.ajax/), async:false (aka. sync mode) does not support cross-domain and dataType: "jsonp" requests.
I am experiencing random occurrences of caching of Ajax requests created through Jquery's get.
The Jquery gets are done in the most straight forward conventional way (route + params + callback)
I am already using
$.ajaxSetup({cache:false});
But it doesn't seem to always work. I get how ajaxSetup no cache works, and I see the added random parameter being added to my request url.
My current browser is IE 8.0
Does anyone know of another solution besides the ajaxSetup way...
The browser itself is simply not allowed/able to cache requests with distinct parameters, as added by {cache:false}.
It sounds like the caching is happening somewhere else in your chain, possibly in your web server/app.
Use firebug's net tab to check exactly what is being requested by the browser, and what the URLs are exactly, then take it from there.
It turns out I was wrong about my assumption about caching of ajax requests.
The real issue was caching of subsequent redirect to action requests that took place on the server (in response to the original ajax call).
The solution ended up being the following attribute.
[OutputCache(Location = OutputCacheLocation.None)]
It can be either applied at the controller level or the action level.
I've configured mod_rewrite on the site, and all URLs look like site.com/smth/else
In profile section of the site I want to make ajax navigation, so URLs will be changed with hashes: site.com/profile#smth
Can I make these ajax URLs look like others (with slashes but not hashes) - is it possible?
It is not possible. The only possible way to change current url without reloading of the whole page - is to change its anchor part.
I want to post some ad to CraigList webiste using this URL. https://post.craigslist.org/nyc/S/fud/mnh/all I know AJAX is a solution which can perform where there is no same origin policy restriction.
The unique thing about this URL is that it modifies the action attribute of the form every time you refresh the page and I can't just post to a single static URL. I wonder is there a way I can automate this URL using AJAX?
I am using JQuery and know how to post a URL but this is headache.
You won't be able to use AJAX as it violates the same origin policy. You can use a regular POST, but you will have to parse the page for the hidden fields etc. to make it work.
Craigslist has gone into a lot of problem to make automated posting very difficult, so I wouldn't bother.