473,804 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

missing } returned to AJAX posted

63 New Member
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 1345
acoder
16,027 Recognized Expert Moderator MVP
Can you post an example array that shows up this error.
Mar 12 '08 #2
Tarik Monem
63 New Member
The error reads exactly:

Error: missing } in XML expression
Source file: http://www.somedomain. com/someJSFile.js line 97
javascript:mySe Func([{SHOWS:"some_sh ow",GENDER:"Mal e",...

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 Recognized Expert Moderator MVP
Where is this piece of code being echoed?
Mar 12 '08 #4
Tarik Monem
63 New Member
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 Recognized Expert Moderator MVP
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
Tarik Monem
63 New Member
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 ExternalInterfa ce.call from the Flex application, which calls a javascript function sendRequestPost 2():

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 "someArrayComin g" 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 Recognized Expert Moderator MVP
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
Tarik Monem
63 New Member
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 myActionScriptF romJavascript 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 Recognized Expert Moderator MVP
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
3092
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 user clicks back with their selected options still selected - and I'm getting to the point where I might just popup a big window, perhaps with some flash in it and say "dont be lazy, select em again you great big freak of nature" because I am...
4
7712
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 Ajax.Request( url, {method: 'post', parameters: params, onComplete: evalInfo }); function evalInfo( request ) { // do stuff with request
1
3062
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 but in online French accents are missing. The text displays like this “de r?isation pour regroup?a majorit?es “. I declared following code in the head section of the file. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
8
3121
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 press a button in the first page. The returned HTML in the div has another button, which, when pressed, should call the same perl script again. Think of the program as some sort of wizard. The problem is, this works perfectly as expected in FF...
1
1268
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 solution and wondering for a while why the classes did not show up. It was because the properties for the class file were "content" rather than "compile". Also copied all my images to a newly created image folder outside the IDE. There is no...
7
1899
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 Ajax?
9
1216
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
1727
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 ScriptManager.Registerxxx methods ? Regards CS
7
2099
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
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.