Encountered an issue when attempting to perform a cross domain ajax request.
Error message: NetworkError: DOM Exception 19
Seeking assistance with this problem. Feeling very stuck and frustrated :(
Encountered an issue when attempting to perform a cross domain ajax request.
Error message: NetworkError: DOM Exception 19
Seeking assistance with this problem. Feeling very stuck and frustrated :(
Encountered an issue in Chrome when making synchronous requests:
let request = new XMLHttpRequest();
request.open("GET", url, false); // false indicates synchronous call
request.send();
Switching to asynchronous (which was my original intention) resolved the error.
Upon further investigation, I realized that the server was rewriting the URL. Using the rewritten URL prevented the error from occurring. This behavior seemed like a bug specific to Chrome, as Safari handled the synchronous calls with non-rewritten URLs without any issues.
Considering that synchronous XMLHttpRequests are deprecated, I'm undecided about reporting this potential bug.
One mistake that is frequently made is attempting to send a https request to a server that is set up for http connections.
In order to make cross-domain AJAX calls function properly, I implemented a solution using PHP on the server side.
getRemoteUrl.php
<?php
if (preg_match("/^[();[]{}]+$/", $_GET['url'])) {
//Handle malicious input
} else {
$ctx = stream_context_create(array('http' => array('timeout' => 10)));
if (!(@$contents = file_get_contents($_GET['url'], 0, $ctx))) {
//Action in case of failure
} else {
//Action in case of success
echo $contents;
}
}
?>
Then, you can call the PHP file and utilize the output as though you were accessing the website directly.
function GetXmlHttpObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
return null;
}
}
var xmlhttp = GetXmlHttpObject();
if (xmlhttp === null) {
//Your browser does not support XMLHTTP!
} else {
xmlhttp.open("GET", "getRemoteUrl.php" + "?url=someRemoteUrl", false);
xmlhttp.send();
var webpage = xmlhttp.responseText;
//Perform actions with retrieved webpage content
}
It is advisable to use asynchronous operations instead of synchronous ones for better performance. If PHP is not your preferred choice or unavailable, similar solutions can be implemented using other server-side languages.
Error code DOM Exception 19 indicates a "Network Error". Have you verified that the URL being used in your Ajax call is accessible?
If the server allows it, cross domain requests can be made! Prior to the GET/POST call, the browser sends an OPTIONS request to the server to confirm if cross domain requests are supported. Make sure to verify if the server permits cross domain requests. For further information on cross domain requests, you may find this article helpful: Understanding CORS
To overcome the cross-domain policy restrictions of a server, you have the option to utilize Korz. Simply include this line in your code:
<script src="//tomodo-tools.s3.amazonaws.com/tomodo.korz-0.5.js"></script>
Add this script to the <head>
section of your website and all cross-domain requests will be redirected through tomodo.me, ensuring that their
Access-Control-Allow-Origin header
is set to '*'
Summary: If you prefer, I have a video detailing my issue: https://youtu.be/Qf9Q4zIaox8 Concern with Navbar Component Not Updating on Store Change. The issue I'm facing involves the Navbar component not updating when there is a change in the store. ...
I'm facing an issue with populating a three-tier dependent dropdown in Angular with saved cookies. Sometimes, all three tiers populate correctly, but other times they show as blank strings or only partially populated. Upon inspecting the HTML code, I ...
Currently, I am enrolled in a node.js course through frontendmasters.com. In this particular course, it seems to have been recorded at least a year or two ago. The instructor initiates by setting up an application directory called 'express', then ...
I've developed an "interaction tracker" system that collects anonymous data on clicked page elements. By implementing an event listener for clicks on the body, I can track interactions with any element on my site successfully. However, interestingly ...
How can I filter out book data based on the author's id? I have a list of books with various author ids, and I want to only return the books that match a specific author id. However, my current filtering method doesn't seem to work correctly as i ...
As I embark on my journey to learn JavaScript, I decided to tackle some exercises on exercism.io. This platform provides pre-written tests that need to be passed. While things were going smoothly initially, I hit a roadblock with the latest exercise where ...
I am currently trying to replicate a password hashing algorithm in node.js (using LTS version 14.x) that was initially coded in PHP (version 7.2). Despite my efforts, the node.js implementation I have created seems to deviate from the original after the fi ...
Looking to set up a periodic update for this ajax fetch function, say every 10 seconds. I've tried a few approaches but none seem to work as expected. That's why I'm reaching out here for help. So, any idea how I can refresh the content ev ...
I am working with two tables: Company and Category. I need to retrieve two columns from the Company table and one column from the Category table when a user types in the textbox. An example of the search parameters is as follows: --- CategoryName Suburb S ...
I am currently attempting to implement the example found at in a React-Three-Fiber environment. My code is encountering several issues. Firstly, I am consistently receiving the following warning in Chrome: [.WebGL-0x26d30384f700] GL_INVALID_ENUM: Enum i ...
For example, check out this JSFiddle link. The interesting part occurs during the mousedown event: var hits = raycaster.intersectObjects( [object1, object2, object3] ); if ( hits.length > 0 ) { console.log(hits[ 0 ].object) hits[ 0 ].object.m ...
I'm currently facing challenges while working on a form to enable a button when certain conditions are met. The form I created includes fields for name, phone number, options, and a message. Once all requirements are filled, I aim to re-enable the di ...
Currently, I am implementing ajax to increment the click count on a post (post_meta). However, I've encountered an issue where if a user is not logged in on Wordpress, the ajax response returns the entire page content instead of the desired output. I ...
Having trouble getting a button to call the getFilteredRows() function in my MVC app's view and controller. I've tried various combinations, but the button just won't trigger the function. Can anyone help me figure out why? @using ProjectEx ...
In my AngularJS view, I have a dropdown that triggers a function when the color is changed: <select ng-change="shop.updateSizes()" ng-model="shop.color" ng-options="color.name for color in COLORS"></select> The updateSizes method in my contro ...
After running my Java code, the returned Collection (ArrayList) produces JSON through JAXB that looks like: {"todo":[{"name":"CAMPBELL","sales":"3","time":"1331662363931"}, {"name":"FRESNO","sales":"2","time":"1331662363931"}]} However, I am wondering if ...
I have developed an application that uses ajax to send json data to a Google form. However, I am encountering difficulties in sending all the desired data, specifically content within a textarea and select tag. To work around this issue, I have hidden some ...
Working with Vuejs and Vuikit components, I have set up the following structure: <template> <div class="uk-scope"> <vk-modal :show="isShow" v-if="config"> <vk-modal-close @click="alert('hello!')" large& ...
Currently, I am tackling the challenge of implementing JWT authentication using Angular and Java Jersey. I have successfully managed to send the JWT token from the server to the client, which can be observed as a POST response with a status code of 200 in ...
I am currently developing a MEAN application based on the template provided by Linnovate. You can find the template at https://github.com/linnovate/mean My goal is to integrate a module called Cloudinary into my application. To achieve this, I followed th ...