Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 972973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:12:37+00:00 2026-05-16T03:12:37+00:00

Here is my problem: I’m developing a system that can be polled to retrieve

  • 0

Here is my problem: I’m developing a system that can be polled to retrieve dynamic data. It’s in Grails, and when I do a request on a certain controller action, say “http://localhost:8080/foo/bar“, a JSON list is returned containing the latest data.

For added security and functionality, I protected my page using Spring Security (Grails Acegi plugin), with Basic Authentication enabled. When you log in, the system automatically loads information regarding your user profile, and that changes the data that is returned. So, authentication is mandatory.

This works: I can poll my action from any browser, and the data will be returned. I have a JavaScript script in my Grails application that calls this URL.

The problem is that I would like to externalize my JavaScript script to distribute it to customers, so they can build their own HTML file, plug in my JavaScript file, and be able to access my data (kind of like an API) using AJAX. Like so:

$.ajax(url: urlWithParams, 
       method: 'GET', 
       beforeLoad: function(xhr) { 
           xhr.setRequestHeader('Authorization', authString);
       },
       success: myFunction
});

However, it doesn’t work. First of all, I know cross-domain GET requests are tricky. But in my case, I use Basic Authentication, which is trickier, because I need to put the credentials into the XmlHttpRequest directly, and that produces preflighted requests in Firefox (replacing GET by OPTIONS), and my Grails application doesn’t deal with it.

My problem is very specific. I use Basic Authentication to prevent malicious access, however I can’t access my application using proper credentials because of some cross-domain restrictions!

What should I do! I tried with an IFrame, but I can’t get the page content (I get an “Access Denied” error – yet again cross-domain restrictions).

Also, jQuery username and password fields in the ajax() function don’t work.

Could I do a simple AJAX GET request on an unprotected page, sending credentials as parameters, and then the page would redirect to the protected page using the credentials? The browser wouldn’t mangle the request, but can I do a redirect with Basic Authentication credentials?

I have a feeling that it won’t work (something to do with the redirect, which generates a new request, etc…). Am I right, or should it work?

Could JSONP solve this problem? I don’t know how to integrate Basic Authentication using JSONP, however…

Thank you very much!

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:12:37+00:00Added an answer on May 16, 2026 at 3:12 am

    I solved my question using JSONP. I modified my application so as not require basic authentification for the AJAX call. The $.getJSON() method from jQuery did the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a problem here with an MSI deployment that I'm working on (using
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
I have a problem here using .dbf files. I can make CRUD operations but
everyone I got problem here I need to update a plist data in a
Just a small SVN problem here. I setup my own SVN server Setting up
I'm having a bit of a problem here. We have 2 urls let me
I've got a Schroedinger's Cat type of problem here -- my program (actually the
This is in reference to the question previously asked The problem here is, each
Here's a problem I ran into recently. I have attributes strings of the form
Here's the problem, you include multiple assemblies and add 'using namespaceX' at the top

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.