By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

passing Arrays to flex via AJAX, receiving illegal character error

P: 63
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
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
I think you're not closing the double quote for the link.
Nov 17 '07 #2

P: 63
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
Expert Mod 15k+
P: 16,027
Glad you got it working. Good stuff!
Nov 19 '07 #4

Post your reply

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