Alternative solution to fix navigation issue in Flex 4.5 when navigatetoURL is not functioning as intended

Perhaps you are aware of the compatibility issues that Google Chrome and Safari have when using navigatetoURL, as it only works in Internet Explorer. To address this problem, I found a code snippet on a forum which consists of a JavaScript function embedded in an HTML file. Additionally, there is another function in Flex that gets called when a button is clicked. Here's a snippet of the code:

variables.pmsg1 = xml_langue.msg1;
variables.pmsg2 = xml_langue.msg2;
variables.pmsg3 = xml_langue.msg3;
variables.pmsg4 = xml_langue.msg4;
variables.ppaytomode = parentApp.PAYTOMODE;
var request:URLRequest = new URLRequest(dir_web);
request.data = variables;
request.method = "GET";
//navigateToURL(request,"_blank");
postXMLPageRequest(variables, request.toString(), '_blank'); // HERE I AM CALLING THE FLEX FUNCTION

THE FLEX FUNCTION BELOW:

public function postXMLPageRequest(data:Object, pageURL:String, window:String=null):void { if (ExternalInterface && ExternalInterface.available) ExternalInterface.call("postXMLPageRequest", pageURL, data.encode().toString(), window); }

THE JAVASCRIPT FUNCTION (found in html file) BELOW:

function postXMLPageRequest(url, xmlString, target, method) { method = method || "POST"; target = target || "_blank";

<%----------------------------------------------------------%> <%-- Create a form element with the specified attributes. --%> <%----------------------------------------------------------%> var form = document.createElement("form"); form.setAttribute("action", url); form.setAttribute("method", method); form.setAttribute("target", target); form.setAttribute("ENCTYPE", "text/plain"); form.setAttribute("style", "display: none");

<%--------------------------------------------------------------------%> <%-- Add the XML string as the value to a hidden input to the form. --%> <%--------------------------------------------------------------------%> var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", "' + xmlString); form.appendChild(hiddenField );

<%-----------------------------------------%> <%-- Add the form to the body, submit it --%> <%-- then remove the form from the body. --%> <%-----------------------------------------%> document.body.appendChild(form); form.submit(); document.body.removeChild(form); }

However, upon clicking the button that triggers the postXMLPageRequest function, nothing seems to happen. Can anyone provide insight into solving this issue?

Thank you!

Answer №1

Upon reviewing the code, three issues caught my attention immediately. Firstly, there is a mistake in how you are utilizing the flex function:

postXMLPageRequest(variables, request.toString(), '_blank');

The URLRequest object does not have a toString() method; to get the URL string, use request.url instead.

The second issue lies in a syntax error within your javascript code. You have used a combination of double and single quotes instead of a pair of quotes in:

hiddenField.setAttribute("name", "' + xmlString);

Lastly, while indicating a GET request in the flex method call, you failed to pass a method type string into the javascript. To execute a GET request, ensure that "GET" is passed as the fourth parameter of the ExternalInterface call; otherwise, it defaults to POST.

I trust this information proves beneficial to you.

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

Inserting data into a table using variables in Mssql database management system

I'm really struggling to find a way to safely add my Variables into an MSSQL server. I've tried everything. Could someone please help me and provide the solution for adding my Variables into the Database? It is crucial that I prevent any possib ...

Incrementing and decrementing a variable within the scope in AngularJS

Objective: When the next/previous button is clicked, the label on the current slide should change to display the next/previous category. View the Category Slider Wireframe for reference. Context: I previously tried a solution called 'Obtain Next/Prev ...

Upon refreshing the datatable, I encountered a issue where the checkbox cannot be selected

After updating my data table with new content through an AJAX request, I am facing an issue where I am unable to select the check-boxes in the table. I use a class selector to choose the rows that contain multiple check-boxes. The select event is placed in ...

Is there a way to send the image's name as a parameter?

I am facing a challenge in achieving a specific task and need some guidance. My current approach involves passing the image name as a parameter to the cancelimage.php script, but it seems like I am not utilizing the variable 'image_file_name' cor ...

Transferring extra data from jQuery autocomplete to a PHP script

Hey there! I'm wondering if it's possible to pass extra parameters from jQuery autocomplete to a PHP page, which would then use them to query a database and return the results. While I know how to send the typed term from the input box, I'd ...

javascript onload select the text in the textarea

Is there a way to have JavaScript automatically highlight the text inside a textarea when the page is loaded? ...

Using VBA and Selenium to access iframes within HTML with the #document tag

I am currently facing a challenge in accessing the HTML content within two iframes using Selenium Basic in VBA. Due to restrictions on our machines, we are unable to use IE and other tools like Python are not available to us. In the past, I was able to ac ...

What is the best way to maintain the position of components (such as a Card component) when one is expanded in a Material-UI and ReactJS project

Currently, I am working with an expandable Card component from Material-UI and using flex for aligning the components. However, when one card expands, it affects the positioning of the other components in the row: https://i.stack.imgur.com/vGxBU.png What ...

Using JS to switch between text and state in ToneJS

I am facing an issue with the text not displaying in the "play-stop-toggle" element, despite my limited experience with JS. My desired outcome includes: [SOLVED] The text in <div id="play-stop-toggle" onclick="togglePlay()">Play ...

Signing off from GitHub Packages for npm

As I work on a project that utilizes a private GitHub package, I have been using it locally with the command npm login --registry=https://npm.pkg.github.com. However, this approach has posed problems when attempting to deploy the project in a production en ...

Utilizing Cookies in an AJAX Request for Cross-Domain Communication with Pure Javascript

I am in the process of developing an Analytics application and I'm seeking a method to uniquely identify each user's device. Currently, my approach involves generating a "cookie" from the server side to track all page clicks and interactions thro ...

Facing issues with jQuery and Bootstrap: ERR_CONNECTION_RESET

My jQuery and Bootstrap are causing issues and showing the following error message: GET net::ERR_CONNECTION_RESET GET net::ERR_CONNECTION_RESET Imports: jQuery: <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> ...

The query pertaining to Facebook redirect functionality

I have a Facebook ad with a URL encoded in it, and I need to extract the final destination URL that it redirects to using JavaScript in my Python program. The standard urllib2/mechanize methods don't work because of the JavaScript involved, and as a P ...

Merging SCSS and CSS into a unified file using WebPack

Trying to grasp webpack as a beginner is proving to be quite challenging for me. I'm struggling with the concept of merging multiple scss and css files together using webpack, after transpiling the sass. Unlike gulp, where I could easily transpile sa ...

Each time `fs.writeFile` is invoked, it initiates a fresh line

Every time this code is run, I want it to create a new line of data instead of overwriting the previous one. For example, if it's executed once, it would display: Checked Status: ONLINE. However, upon subsequent runs, it should add another line direc ...

Tips for improving performance with ng-repeat directive?

I have encountered some performance issues while using socket.io with the ng-repeat directive in Angular. The application slows down significantly when receiving a large amount of data from the backend, making it impossible to interact with the app. What w ...

Executing multiple calls with Angular's $http service and then resolving them within a loop using underscore

I am facing an issue while trying to fetch multiple data from $http inside _.each function and display the combined data in $scope.tasksData. The problem I encountered is that _.each is being executed later, causing it to return null first. Can someone pl ...

Is there a way to retrieve nested data from a JSON API response?

Trying my hand at creating a basic CLI cryptocurrency tracker app. The app runs a successful API call and provides the following output: [ { exchange: 'binance', base: 'ADA', quote: 'BTC', price_quote: '0.000 ...

Event follows activation of trigger click

I've already gone through this post on Stack Overflow about triggering an action after a click event, but none of the solutions I've tried so far have worked. Let's say I have a menu on my webpage like this: <ul class="nav nav-tabs"&g ...

Having trouble implementing server-side rendering with Styled-Components in Next JS

I attempted to resolve my issue by reviewing the code and debugging, but unfortunately, I couldn't identify the root cause. Therefore, I have posted a question and included _document.js, _app.js, and babel contents for reference. Additionally, I disa ...