Navigating to an external URL using HTTP GET

I need to create a function that retrieves plain text from a public URL and use it for validation purposes.

I attempted to do this using the Dojo AJAX GET method, but encountered issues when trying to access a different domain (only works on Explorer).

How can I successfully make a call to an external domain and handle the response?

The URL will be similar to:

http://my.socket:8080/?option1=1&option2=2

This can be accomplished using either AJAX or a Java class.

Answer №1

Client-side ajax operates within the constraints of the Same Origin Policy, preventing foreign domain ajax calls to be made.

To work around this limitation, it is recommended to handle GET requests on the server side of your application and then use ajax to make a call to your application as a gateway to fetch data from a remote server.

Answer №2

Because of the same origin policy, performing simple ajax calls across different domains is restricted.

One way to work around this limitation is by making an ajax call to a server page on the same domain, which can then execute an HTTP get request to retrieve the content for you.

Alternatively, you can utilize YQL

var url = 'http://my.socket:8080/?option1=1&option2=2'; // website you want to scrape
var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + url + '"') + '&format=json&callback=?';  
$.getJSON(yql,function(data){  
    if(data.query.results){
        var result = data.query.results.double.content.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
        alert(result);
    }
});

Source

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Show data retrieved by an AJAX call in a user interface

Through an ajax call, I successfully retrieved data from active directory. The PHP file used for this ajax call to active directory can be found here. Upon inspecting the browser console, the ajax call output includes information such as sn, givenname, e ...

Setting up only two input fields side by side in an Angular Form

I'm fairly new to Angular development and currently working on creating a registration form. I need the form to have two columns in a row, with fields like Firstname and Lastname in one row, followed by Phone, Email, Password, and Confirm Password in ...

Unable to show information within a view in an Express Node.js application

Just diving into the world of express and node, I'm currently working on a basic express app that retrieves data from a json file. However, when I try to render the data on my post/details view, it doesn't seem to show up. I suspect the issue lie ...

Is there a way to invoke a function using a variable in place of its actual name?

Check out my code snippet: $('.click').on('click', function(){ $.ajax({ url : $(this).siblings('a').attr('href'), dataType : 'JSON', success : function (tags) { $ ...

I'm encountering an issue when trying to send a list of data to MVC

I am working with the following model: public class CompanyDto { public string CompanyName { get; set; } public IEnumerable<CompanySocialNetworkTypeDto> CompanySocialNetworkTypeList { get; set; } } public class Compan ...

Can the outcomes be showcased again upon revisiting a page?

Whenever I navigate away from and return to my filter table/search page, the results vanish. I'm looking for a way to preserve the results without reloading the page. Essentially, I want the page to remain as it was originally, with the search results ...

Numerous data displayed upon clicking an item on the recyclerview

I am facing an issue where, when I try to show the chatlist and click on an item, the list in the recycler view appears to be duplicated as shown in picture 1. However, when I change the fragment using the bottom navigation, the list is displayed normally ...

No success with ajax following the execution of a php script

Utilizing a php-script, I am able to execute a database backup of my website with the simple click of a button on the admin-panel. To enhance user experience, I want to display real-time updates in the admin-panel during the backup process, indicating whe ...

Deciphering android assets from XML files

Can someone assist me in resolving an issue I am having with parsing an XML-file for my Android App? I am able to read string values without any problems, but I'm unsure how to convert the XML layout reference to a layout id. Any help would be greatl ...

Adjust the hue of a Three.js-generated 3D cube

Seeking assistance! How can I customize the colors of a 3D cube in the Three.js library rather than using the default settings? This is what I have managed to create so far - HTML <div id="container"></div> JavaScript // revolutions per se ...

Selenium throwing NoSuchElementException in IE7 browser

Having some trouble using Selenium on Internet Explorer 7 with InternetExplorerDriver on a Windows XP system. The code runs smoothly on Firefox, IE9, and even IE9 compatibility mode on Windows 7. Here is the HTML snippet: <HTML xml:lang="fr" xmlns="ht ...

Personalized map pin styling

Currently, I am following a tutorial on this link: http://jsfiddle.net/doktormolle/jcHqt/. However, the rendering of the marker is not up to par, especially when using my own custom marker as it appears quite pixelated. I am looking for assistance in ach ...

Implement interactive buttons on jpanel using Java

I'm currently working on a Java program that aims to display a button in a JPanel upon its click. I have the run method with the following code snippet: public void run(){ panel.addMouseListener(new MouseAdapter() { public void mousePres ...

Why does tween animation appear instant rather than smooth?

I am trying to achieve a camera movement effect where the camera transitions from its current position to the center of a mesh (which is a sphere and I want to be inside of it) when a button is clicked. I have implemented a function with a tween for this ...

Handing back an IBinder

Hey there, I'm a beginner in the world of Android and I'm curious about the highlighted code snippet below. Can someone help me understand the role of IBinder in this context and why an inner class is used for this purpose? public class MyRandom ...

The function 'then' cannot be called on an undefined value in $ajax

My AngularJS controller uses $.ajax to save an order. However, after updating to AngularJS 1.2.2, I encountered the error message TypeError: Cannot call method 'then' of undefined when making the $.ajax call. I couldn't find any information ...

Verification for Android Sign-In

I'm feeling really frustrated with my android login process. I've tried everything, but I can't seem to get it right. Can someone please help me out? Here's the issue: I have a login screen that prompts the user to enter their email and ...

Expanding a collection of text inputs on-the-fly (HTML/JavaScript)

Looking to streamline our data entry process, I am developing an app for in-house tasks. Our team will be required to input information about various "items" that correspond to multiple "categories." To facilitate this task efficiently, I'm explorin ...

Encountering a CORS error after deploying an Angular and Spring Boot application on Heroku

Currently facing challenges with an app due to CORS issues. It functions perfectly locally, but once deployed, an error occurs. Access to XMLHttpRequest at 'https://portafolioback.herokuapp.com/portafolio/version1/post/all' from the origin &apos ...

The method "_super" is not supported by the object in igGrid

When using infragistics and igGrid in my application, I encountered a javascript error. The error message reads: "Object doesn't support property or method "_super" Although I understand how to resolve this issue, I have decided to provide a fake ...