0
votes

Maybe you all know about the issue GoogleChrome and Safari has with using navigatetoURL. It works only in IE. Thus I gathered the following code from a forum. The code is a javascript function place in the html file. Then there is another function in Flex, which is called when a button is clicked. Part of the code is here:

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 nothing is being executed when I click the button which calls the postXMLPageRequest function> CAn somebody help me with this?

Thanks a lot.

1

1 Answers

0
votes

There are 3 issues I see right away. First, you are calling your flex function using

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

Even though it extends Object, URLRequest doesn't actually have a toString() method. request.url is the correct way to get the url string.

The second is that you have a syntax error in your javascript. You have a double quote and a single quote rather than a pair of quotes in

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

Third, you indicate in your call to the flex method that you want to do a GET request. You never actually pass a method type string into the javascript though. If you want the do a get you need to pass "GET" as the fourth parameter of the ExternalInterface call. Otherwise it will default to POST.

Hope that helps.