473,398 Members | 2,088 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,398 software developers and data experts.

missing } returned to AJAX posted

Hi guys, it's me one more time today.

I have a PHP file echoing an array back to a javascript file.

Here's the Array being generated:
Expand|Select|Wrap|Line Numbers
  1. $myTempArray[$count] .= "{SHOWS:\"".htmlentities($shows_new2)."\",GENDER:\"".htmlentities($gender_new2)."\", AGE:\"".htmlentities($age_new2)."\",FIRST_NAME:\"".htmlentities($user_first_name_new2)."\", LAST_NAME:\"".htmlentities($user_last_name_new2)."\",EMAIL_ADDRESS:\"".htmlentities($emailaddress_new2)."\", PHONE_NUMBER:\"".htmlentities($phone_number_new2)."\", CITY:\"".htmlentities($city_new2)."\",STATE:\"".htmlentities($state_new2)."\", ZIP:\"".htmlentities($zip_new2)."\",PICTURE:\"".htmlentities($picture_new2)."\"}";
  2. $count++;
  3.  
  4. echo "javascript:mySeFunc([".$myTempVar."]);";
  5.  
When it sends the array to the Javascript file, then I receive an error in the JavaScript error console that the "}" is missing.

What can I do, I've been using this method for many of my applications, but this is the first time that I've encountered this issue.

I've tried stripslashes, addslashes, htmlentities, etc... but nothing seems to send the entire array without receiving some kind of error.

As usual, thanks in advance :-)
Mar 12 '08 #1
9 1324
acoder
16,027 Expert Mod 8TB
Can you post an example array that shows up this error.
Mar 12 '08 #2
The error reads exactly:

Error: missing } in XML expression
Source file: http://www.somedomain.com/someJSFile.js line 97
javascript:mySeFunc([{SHOWS:"some_show",GENDER:"Male",...

The arrow appears after the colon following SHOWS.

It's like it is not reading the entire array as a string.

Thanks in advance
Mar 12 '08 #3
acoder
16,027 Expert Mod 8TB
Where is this piece of code being echoed?
Mar 12 '08 #4
Expand|Select|Wrap|Line Numbers
  1. echo "javascript:mySeFunc([".$myTempVar."]);";
  2.  
From there the javascript file takes the echo:
Expand|Select|Wrap|Line Numbers
  1. window.onload = eval(response);
  2.  
Which calls the function to send the array to a datagrid within a Flex app:
Expand|Select|Wrap|Line Numbers
  1. function mySeFunc(someArrayComing)
  2. {
  3.     var flexApp = FABridge.fab.root();
  4.     flexApp.myActionScriptFromJavascript(someArrayComing);
  5. }
  6.  
I've been doing this with several applications and I don't know why this one is giving me such a hard time. For a while I thought it was because some of the data in the DB had apostrophes in their names, but I use addslashes(), so I don't think that this is issue.

And the arrow is always following the colon ":" character. Why would javascript have a problem with ":"?
Mar 12 '08 #5
acoder
16,027 Expert Mod 8TB
That still doesn't explain where the echo is called within the HTML code. From the "javascript:" protocol, I assume it's within a link tag?
Mar 13 '08 #6
I'm sorry if I mis-understood, but I believe you are asking what initiates the echo. If this is the case, then the answer would be an ExternalInterface.call from the Flex application, which calls a javascript function sendRequestPost2():

Expand|Select|Wrap|Line Numbers
  1.     var phpscript2 = '../../two_arrays_into_one.php';
  2.  
  3.     function createRequestObject() 
  4.     {    
  5.         var req;
  6.  
  7.         if(window.XMLHttpRequest)
  8.         {
  9.             // Firefox, Safari, Opera...
  10.             req = new XMLHttpRequest();
  11.         } 
  12.         else if(window.ActiveXObject) 
  13.         {
  14.             // Internet Explorer 5+
  15.             req = new ActiveXObject("Microsoft.XMLHTTP");
  16.         } 
  17.         else 
  18.         {
  19.             // There is an error creating the object,
  20.             // just as an old browser is being used.
  21.             alert('There was a problem creating the XMLHttpRequest object');
  22.         }    
  23.         return req;    
  24.     }
  25.  
  26.     // Make the XMLHttpRequest object
  27.     var http = createRequestObject();
  28.  
  29.     function sendRequestPost2() 
  30.     {
  31.         // Open PHP script for requests
  32.         http.open('post', phpscript2);
  33.         http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  34.         http.onreadystatechange = handleResponsePost;
  35.         http.send('userid=1');
  36.         //window.onload = eval('javascript:writeMyHtmlFunction('+session+','+id+');');
  37.     }
  38.  
  39.  
  40. function handleResponsePost() 
  41. {
  42.     if(http.readyState == 1)
  43.     {
  44.         document.getElementById("response2").innerHTML = "Please wait, loading... " ; 
  45.     } 
  46.     else if(http.readyState == 4 && http.status == 200)
  47.     {
  48.  
  49.         // Text returned from PHP script
  50.         var response = http.responseText;
  51.  
  52.         if(response) 
  53.         {
  54.             // document.getElementById("response2").innerHTML = response;        
  55.             window.onload = eval(response);
  56.             // mySeFunc();
  57.         }
  58.     }
  59. }
  60.  
  61.  
The function of course calls the PHP file which logs into the database, retrieves the data and then returns the values via the echo:

Expand|Select|Wrap|Line Numbers
  1. echo "javascript:mySeFunc([".$myTempVar."]);";
  2.  
The echo is then called to action via the JS file:
Expand|Select|Wrap|Line Numbers
  1. window.onload = eval(response);
  2.  
Which the JS code for the mySeFunc is as follows:
Expand|Select|Wrap|Line Numbers
  1. function mySeFunc(someArrayComing)
  2. {
  3.     var flexApp = FABridge.fab.root();
  4.     flexApp.myActionScriptFromJavascript(someArrayComing);
  5. }
  6.  
Now, if I substitute "someArrayComing" for values then it works fine and populates the datagrid. If I substitute "response" for values, then once again, it works fine and the datagrid is populated with no errors. That means that somewhere between the echo within the PHP --

Expand|Select|Wrap|Line Numbers
  1. echo "javascript:mySeFunc([".$myTempVar."]);";
  2.  
  3. and JS:
  4.  
  5. window.onload = eval(response);
  6.  
would be the issue. Since the server crashed two Sundays ago, this application has not been functioning the way that it was able to. Before the IT Admin that we have now, there was someone who previously maintained the server and this server is set to all default settings. Is there some kind of tweek to the configurations of the server, PHP wise, that would cause PHP not to be able to send a string with a ":" character to JS?

Everything about these files works, except sending a string with a ":" character via the paramater "response." If I copy and paste the same data that was echoed via JS:
Expand|Select|Wrap|Line Numbers
  1. // document.getElementById("response2").innerHTML = response;
  2.  
which I commented out, then it works fine. The problem is between the PHP echo to the JS's "response" param. How is it possible for this code to have worked perfectly, then the server crashes, the new server is set to default settings and now the application doesn't function as expected.

There has to be something to the configuration of php.ini that is causing this block.

Thanks in advance
Mar 13 '08 #7
acoder
16,027 Expert Mod 8TB
The use of "javascript:" is not really needed.

I'm wondering why you're assigning to window.onload. Does mySeFunc return a function? It doesn't seem to.
Mar 14 '08 #8
Actually, mySeFunc does return a function to the Flex application and populates the datagrid with the info within the param being passed:
Expand|Select|Wrap|Line Numbers
  1. function mySeFunc(someArrayComing)
  2. {
  3.     var flexApp = FABridge.fab.root();
  4.     flexApp.myActionScriptFromJavascript(someArrayComing);
  5. }
  6.  
Here is the myActionScriptFromJavascript function within the Flex app:
Expand|Select|Wrap|Line Numbers
  1.         public function myActionScriptFromJavascript(someArrayComing:Array):void
  2.         {
  3.             dataGrid.dataProvider = someArrayComing;
  4.             dataGrid.validateNow();
  5.         }
  6.  
So, I believe that I have to differ with you on needing JavaScript, because that is the way I have been populating the datagrid within Flex, is by using the FABridge method of making a bridge between JS & Flex.

The strange thing about all of this, is that this all worked perfectly before the server crashed two Sundays ago. The IT guy restored to server to all default settings. Is there some kind of setting in the php.ini that would prevent PHP from sending a string via a param, that may have been changed by returning to the default settings.

The reason why I ask this question, is because I have taken the data that is echoed by the PHP file, copied & pasted in place of the variable "response" and it populates the Flex Datagrid with no problems or errors.

Obviously, something is dieing between the PHP and the JS file:
Expand|Select|Wrap|Line Numbers
  1. echo "javascript:mySeFunc([".$myTempVar."]);";
  2.  
  3. and 
  4.  
  5. window.onload = eval(response); 
  6.  
And why did this work for months, then die a couple of weeks ago.

Thanks in advance
Mar 14 '08 #9
acoder
16,027 Expert Mod 8TB
The fact that this was working fine before the server crash means that what I'm explaining may not be helpful, but all the same...

What I was saying was that when you assign something to window.onload, it is usually a function object to run when the window has loaded, not a function which is run immediately and the result assigned to it (unless the function returns a function object itself).

I'm not sure why you're assigning to window.onload after the page has loaded, but there you go.

I can't really explain why it's not working, but as you say, most likely it's some server setting which doesn't send the response in the right format. Perhaps you need to check the headers.
Mar 16 '08 #10

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

Similar topics

6
by: Rob Meade | last post by:
Hi all, Looking for a bit of help if possible. For about 2 weeks now I've been investigating the best way to populate related drop down menus, and have their values pre-populated again if the...
4
by: ext237 | last post by:
Simple ajax call seems to have some issues in Firefox. The "onComplete:" is called BEFORE the response is returned by the call. Is there a coding issue or a work around? var ajax = new...
1
by: bssjohn | last post by:
Dear All, I have developing a French website using PHP & Ajax. In that I tried to display some French texts from mysql database using Ajax. Form local I got the text from db with Correct accents...
8
by: Samik R. | last post by:
Hello, I am using the innerHTML property of a div placeholder to update the contents, and the HTML is provided from a perl script on the server side. The perl script gets called through AJAX when I...
1
by: Lloyd Sheen | last post by:
I have just completed (almost) an exercise to convert a web site to a web app (acedemic reasons - just to see the differences). A few bumps on the road such as copying class files to the new...
7
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
We are looking at Ajaxing our existing web application. Question is...Should we Ajax any and everything we can, or not? One example...if a page posts back to itself, is that a good candidate for...
9
by: Tarik Monem | last post by:
Hi guys, it's me one more time today. I have a PHP file echoing an array back to a javascript file. Here's the Array being generated: $myTempArray .=...
4
by: WT | last post by:
Hello, How could we simulate the IsClientScriptBlocRegistered method of ClientScript when we use an update panel and the static ScriptManager ? Is this test already included in the...
7
by: Joe | last post by:
I added some ajax to my asp.net web site and will Ajax just doesn't seem to work. Does Any one PLEASE have any ideas on why Ajax doesn't work on Apache 2.2.6 w/asp.net 2.0
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.