4

Here is the AJAX method that works in Safari, but not in Chrome. Error message follows.

$(document).ready(function(){
  $('.infobutton').click(function(){
    $.ajax({
      url: 'http://apps.nlm.nih.gov/medlineplus/services/mpconnect_service.cfm',
      data: {
        'mainSearchCriteria.v.cs': $(this).attr('data-code-system'),
        'mainSearchCriteria.v.c':  $(this).attr('data-code')
      },
      dataType: 'xml',
      async: false,
      method: 'GET',
      success: function(data){
        console.log('success');
        console.log(data);
      },
      done: function(data){
        console.log('done');
        console.log(data);
      },
      error: function(data){
        console.log('error');
        console.log(data.error());
      }
    });
  });
});

The console output gives the statusText in the error callback as this: "Error: NetworkError: DOM Exception 19". This link talks about DOM Exception 19, but that just says NETWORK ERROR. Not helpful.

I know from other research that Chrome has known issues with security, XSS, etc.

I've tried every suggestion in this SO post, as well as this one. No luck.

Going directly to the URL with that query string works. You can view it here.

Also notice that this isn't part of an application. The html is literally just <button class="infobutton">Click Me</button>. This is just a proof of concept to get the AJAX working.

UPDATE I can also confirm that I get this same error both locally (using the file:/// protocol), and remotely, working on a dev server.

2
  • Does the error occur only when launching the page locally from your system (file:///...), only online or both? Commented Jul 10, 2013 at 19:25
  • I've only tried it locally and on JSFiddle with the same results. Commented Jul 10, 2013 at 19:39

2 Answers 2

1

You'll need to set crossDomain: true, and set up a Location redirect on your domain to point to the nih.gov URL.

One of the ways to get around the restriction is to start the request on a domain that is allowed by policy. In other words, it has to be on the same domain as the JavaScript that is making the request. Your page can then redirect the request to another domain.

Local Page Example

<?php
// http://yourdomain.com/some/url/redirect.php
header("Location: http://apps.nlm.nih.gov/medlineplus/services/mpconnect_service.cfm");
?>

Then, replace the URL in your JavaScript with http://yourdomain.com/some/url/redirect.php. The effect is circumvention of the issue you're experiencing.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer. Can you clarify 'set up a location redirect on your domain'?
Sorry for the late reply. I'll edit in the details for location redirect.
0
  1. In your error handling use console.log(data.status)
  2. Check your request URL - it returns 404 (not found)

Did you try Fiddler2 -great tool for debugging

1 Comment

I'm not sure how you're seeing the request URL return a 404. Returns a 200 for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.