Note that there are some explanatory texts on larger screens.

plurals
  1. POCAS authentication and redirects with jQuery AJAX
    primarykey
    data
    text
    <p>I've got an HTML page that needs to make requests to a CAS-protected (<a href="http://en.wikipedia.org/wiki/Central_Authentication_Service" rel="nofollow noreferrer">Central Authentication Service</a>) web service using the jQuery AJAX functions. I've got the following code:</p> <pre><code>$.ajax({ type: "GET", url: request, dataType: "json", complete: function(xmlHttp) { console.log(xmlHttp); alert(xmlHttp.status); }, success: handleRedirects }); </code></pre> <p>The <code>request</code> variable can be either to the CAS server (<code>https://cas.mydomain.com/login?service=myServiceURL</code>) or directly to the service (which should then redirect back to CAS to get a service ticket). Firebug shows that the request is being made and that it comes back as a 302 redirect. However, the <code>$.ajax()</code> function isn't handling the redirect.</p> <p>I wrote this function to work around this:</p> <pre><code>var handleRedirects = function(data, textStatus) { console.log(data, textStatus); if (data.redirect) { console.log("Calling a redirect: " + data.redirect); $.get(data.redirect, handleRedirects); } else { //function that handles the actual data processing gotResponse(data); } }; </code></pre> <p>However, even with this, the <code>handleRedirects</code> function never gets called, and the <code>xmlHttp.status</code> always returns <code>0</code>. It also doesn't look like the cookies are getting sent with the cas.mydomain.com call. (See <a href="https://stackoverflow.com/questions/1887742/ajax-call-through-cas">this question</a> for a similar problem.)</p> <p>Is this a problem with the AJAX calls not handling redirects, or is there more going on here than meets the eye?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload