Comments (10)
This isn't coming from rack-cors. What version Rails are you using? What are you using to load the application js file?
from rack-cors.
Looks like you're using jQuery? See if passing cache: true
to your ajax call does the trick:
http://api.jquery.com/jQuery.ajax/
from rack-cors.
rails -v: 3.2.12. I'm using asset pipeline. i've done
rake assets:clean
rake assets:precompile
code to query
$.ajax({
beforeSend: function (xhr) {
xhr.setRequestHeader ('Authorization', api_key);
},
cache: false,
dataType: 'html',
type: 'GET',
url: url+'/gwsearch/ajax_search?d1='+d1_val+'&d2='+d2_val,
crossDomain: true,
success:function(result){
$("#display").html(result);
},
error: function(result) {
$('#display').html('Unauthorized client.');
}
rails responds with
respond_to do |format|
format.html #responds with html
if params[:callback]
format.js { render :json => {:items_by_tag => @gw_search_results.to_json}, :callback => params[:callback] }
else
format.js
end
end
from rack-cors.
changed to cache: true, no go unfortunately @cyu
$.ajax({
beforeSend: function (xhr) {
xhr.setRequestHeader ('Authorization', api_key);
},
cache: true,
dataType: 'html',
type: 'GET',
url: url+'/gwsearch/ajax_search?d1='+d1_val+'&d2='+d2_val,
crossDomain: true,
success:function(result){
$("#display").html(result);
},
error: function(result) {
$('#display').html('Unauthorized client.');
}
from rack-cors.
What's causing application.js to load though? Is it in the HTML returned by the ajax_search call?
from rack-cors.
Here's more info on the subject:
I'm not sure if there is a suitable solution for this. Sounds like the best thing to do is to request those scripts outside HTML response.
from rack-cors.
Yes, it's through a script tag in the HTML response
<script src="http://localhost:3000/assets/application.js" type="text/javascript"></script>
I'm going to try the hack in the question you referenced and see if that works first, I'd rather not have to load the scripts outside the html response if I don't have to.
from rack-cors.
Using this worked:
$.ajaxPrefilter('script', function(options) {
options.cache = true;
});
Thanks for the help @cyu
from rack-cors.
@cyu Actually, I'm having the same original problem, which I thought had to do with multiple javascripts being delivered.
After my page is requested through ajax cross domain, it has input buttons on it. When I click one of them, it does this:
<%= form_tag plans_collapse_plans_path, :method => 'post', :remote => true do %>
<%= hidden_field_tag(:plangroup_id, plangroup.id) %>
<%= image_submit_tag "collapse.png" %>
<% end %>
The collapse_plans post will be sent however many times I made the initial ajax request. When I look at the request of the input button, it mentions something in the javascript about cors. Could this have anything to do with rack-cors? Something is being reinitialized or loaded everytime I send the initial ajax request for the page. Is it the input form in the html page or the jquery being reinitialized each time? Is there anything I can set in cors to possibly mitigate this?
from rack-cors.
I'm not exactly sure what the problem is, but I'm guessing that anything to mitigate this is really out of scope of this gem.
Closing this as this issue isn't caused by Rack::Cors.
from rack-cors.
Related Issues (20)
- Tag for v2.0.0 is missing HOT 3
- Does not work with Rack 3.0.0 HOT 1
- My CORS setup blocks bad urls but not POSTMAN requests HOT 3
- Vulnerabilities in included mocha.js HOT 1
- Stripe api with Cloud9 setup
- Is there any CI? HOT 1
- Cookie session related middleware interferes HOT 3
- Remove/Replace Rack::Utils::HeaderHash HOT 7
- delete the confusing `2.0.0` tag since `v2.0.0` exists? HOT 1
- issue comeback duplicate headers because of header name case HOT 3
- Release version 2.0.1 HOT 2
- How to add Access-Control-Allow-Private-Network header in Option response?
- Why is Rails.application.config.hosts required? HOT 1
- Regex origin woes HOT 2
- Upgrade to rails 7.1.1
- Ressource with $ are not handled as expected
- Access-Control-Allow-Origin is returned only if correct Origin header is available
- Documentation for the frame-ancestors directive?
- [SECURITY] CVE-2024-27456 - Insecure File Permissions in rack-cors v2.0.1 HOT 15
- The browser does not store the cookies session
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rack-cors.