user2110655
user2110655

Reputation:

Consuming xml rest web service

I am a bit at a loss as to how to query a Rest web service by http://www.nlm.nih.gov/medlineplus/webservices.html Here is a fiddle of what I currently have: http://jsfiddle.net/mjtaljaard/jnjk4/ But it's not returning anything. Someone mentioned that I have a cross site scripting issue? Any suggestions?

function DoSearch() {


    var searchVal = $('#searchString').val();
    alert('called ' + searchVal);
    var url = "http://wsearch.nlm.nih.gov/ws/query?db=healthTopics&term="+searchVal;
    $.get(url, function( data ) {
        $( "#resultsDiv" ).html( data );
        alert( "Load was performed." );
    });
}

Upvotes: 1

Views: 113

Answers (2)

user2110655
user2110655

Reputation:

My project was in Phonegap and cross-site scripting is not an issue for phonegap. So once I got it loaded on my device, everything worked fine.

Upvotes: 0

Mike Dunker
Mike Dunker

Reputation: 1990

Browser client code cannot directly request data from a different web site directly. This is known as the same-origin policy. This helps protect users from cross-site scripting attacks.

Looking at the description of that web service, there is no mention of CORS (cross-origin resource sharing) or JSONP, which are both common ways of relaxing the same origin policy.

Your best solution is probably to make a call to your own server-side code (which is ok if it has the same protocol and host as the web page), and have your server-side code GET the data. You can then either return the entire payload from the GET to the calling webpage, or modify the response and return only the data you need.

Upvotes: 1

Related Questions