473,237 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

passing Arrays to flex via AJAX, receiving illegal character error

Hi Everyone,

Still a newbie with FLEX, and I've passed arrays using AJAX to FLEX before, but I've never passed links to FLEX.

Basically, this is the OUTPUT, which I wanted, but I'm given an error of "illegal character," from the JavaScript console:

Expand|Select|Wrap|Line Numbers
  1. Error: illegal character
  2.  
  3. Source Code:
  4. javascript:mySeFunc([{LINK: \"<a href=\"http://www.mydomain.com/something\" target=\"_blank\">Something 1</a>},{LINK: \"<a href=\"http://www.mydomain.com/something\" target=\"_blank\">Something 2</a>}...
  5.  
I did not place the "\" character, but rather that is how the Javascript console is reporting the error.

I basically read an xml file, send it to a php file, which returns a string in the form of calling a javascript function, which in turn sends the data to the flex app.

Expand|Select|Wrap|Line Numbers
  1. loadXMLDoc('some_files/categories.xml');
  2. var avar=xmlDoc.getElementsByTagName('a');
  3.  
  4. for (i=0;i<avar.length;i++)
  5.   {
  6.   if (avar[i].nodeType==1)
  7.     {  
  8.     Avars = avar.item(i);
  9.     attr1 = Avars.getAttribute("href");
  10.         myTempArray[i] = '{LINK:"<a href="' + attr1 + '" target="_blank">' + avar[i].childNodes[0].nodeValue + '</a>}';
  11.      }
  12.   }
  13.  
  14.     var response =  myTempArray;
  15.     // alert(response); just to test if the correct info was being transferred.
  16.  
  17.         http.open('post', phpscript);
  18.         http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  19.         http.onreadystatechange = handleResponsePost;    
  20.     http.send("response="+response);
  21.  
  22. -- phpscript
  23.  
  24. <?php
  25.     $response_x = $_POST['response'];
  26.     echo "javascript:mySeFunc([".$response_x."]);";
  27. ?>
  28.  
  29.  
  30. -- handleResponsePost
  31. function handleResponsePost() 
  32. {
  33.     if(http.readyState == 1)
  34.     {
  35.         // document.getElementById("response2").innerHTML = "Please wait, loading... " ; 
  36.     } 
  37.     else if(http.readyState == 4 && http.status == 200)
  38.     {
  39.  
  40.         // Text returned from PHP script
  41.         var response = http.responseText;
  42.         if(response) 
  43.         {
  44.         window.onload = eval(response);
  45.         }
  46.     }
  47. }
  48.  
  49. -- calling the flex app
  50. function mySeFunc(someWordsComing)
  51. {
  52.     var flexApp = FABridge.fab.root();
  53.      // alert(someWordsComing); test to see if correct string
  54.     flexApp.myActionScriptFromJavascript([someWordsComing]);
  55. }
  56.  
I have done this before with returning strings from the db but these are links and I don't know if html tags are what is causing the issue or not

The code within the Flex app is straight forward, I just want to populate the one column datagrid with the array being sent:

Expand|Select|Wrap|Line Numbers
  1.         public function myActionScriptFromJavascript(someTextComing:Array):void
  2.         {
  3.             myDG.dataProvider = someTextComing;
  4.             myDG.validateNow();
  5.         }
  6.  
  7.  <mx:DataGrid id="myDG" height="500" width="150">
  8.      <mx:columns>
  9.          <mx:DataGridColumn dataField="LINK" headerText="LINK" />
  10.      </mx:columns>
  11.  </mx:DataGrid>    
  12.  
I have a handful of flex apps that I use this same logic and they work fine. The only thing that is different, is that with the other apps, I am receiving info from the DB and I am not parsing an XML file -- AND, also in this case -- the data are of links.

But a string is a string, right? It shouldn't matter what I'm sending or where I'm getting the string from, right?

When I do an alert, it shows the contents of the entire array, so I know that's working. Is it hung up on the "<" character? But it can't be that because I removed that portion of the string, just to test that theory and I still get illegal character.

Any help would be much appreciated,
Tarik
Nov 16 '07 #1
3 3504
acoder
16,027 Expert Mod 8TB
I think you're not closing the double quote for the link.
Nov 17 '07 #2
First of all, thank you for replying and you were correct, but that wasn't all that was wrong.

After I took your suggestion:

Expand|Select|Wrap|Line Numbers
  1. myTempArray[i] = '{LINK:"<a href=' + attr1 + ' target=_blank>' + avar[i].childNodes[0].nodeValue + '</a>"}';
  2.  
Not only did I add a double quote following the '</a>' but I also took out the double quotes after "href" and "target"

But it still was giving me an illegal character error with a "\" before a double quote, when I realized that I needed to "stripslashes" before sending it back to the js file.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $response_x = $_POST['response'];
  3.     echo "javascript:mySeFunc([".stripslashes($response_x)."]);";
  4. ?>
  5.  
And that was all she wrote -- it works.

Thanks for the help,
Tarik
Nov 19 '07 #3
acoder
16,027 Expert Mod 8TB
Glad you got it working. Good stuff!
Nov 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tom Heathcote | last post by:
Apologies for posting a flex++ question rather than a C++ question, but there does not appear to be a flex++ newsgroup... I am trying to rebuild some old lexical scanner / analyzer code, which I...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
10
by: vbMark | last post by:
Hello, I am doing this: window.location="page2.php?subj="+subj+"&body="+body; to send information to another page. However, I don't want that second page to show up or display in any way....
8
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
4
by: Nathan Sokalski | last post by:
I am a beginner with AJAX, and have managed to learn how to use it when passing single parameters, but I want to return more than one value to the client-side JavaScript function that displays it....
2
by: luis | last post by:
I'm using ctypes to call a fortran dll from python. I have no problems passing integer and double arryas, but I have an error with str arrys. For example: ..... StringVector = c_char_p *...
10
by: Jules Winfield | last post by:
Guys, I've been designing applications for the financial services industry using MSFT technologies for many years (Win32 API, MFC, and now .NET WinForms). All applications are Internet-based,...
8
by: S. | last post by:
Hi all, Can someone please help me with this? I have the following struct: typedef struct { char *name; int age; } Student;
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.