473,383 Members | 1,759 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,383 software developers and data experts.

missing } returned to AJAX

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 1197
TheServant
1,168 Expert 1GB
[PHP] $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).
" \" " };
$count++;[/PHP]

You have escaped all over the place! I have separated the code to be more readable, and also changed the very beginning from "{SHOWS to {"SHOWS as wellas the end from \"}" to \""}. I recommend using the ' character as well, which would let you define elements with ' and so you wouldn't have to escape (maybe) or stleast eb able to read it easier! Try this code and see how you go.
Mar 12 '08 #2
I tried your ideas of the single "'" character and removing the escape sequences, but the same error returns. The "{" has to be part of the string being sent back to the JavaScript file, so I didn't change the "{" part of it, as you suggested.

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.  
The error has an arrow that appears after the first colon "SHOWS:" if that helps.

Thanks once again.
Mar 12 '08 #3
TheServant
1,168 Expert 1GB
What about trying brackets around the variable input info? I think it's not registering the variable input as a single string:
$myTempArray[$count] = (...);
Mar 12 '08 #4
I tried adding the "(" and ")" and it does not seem to help.

For some reason, it seems to be having an issue with the ":" character after "javascript:mySeFunc([{SHOWS:" -- it does not matter what the first entry is because I have tried to manipulate the data to have other first entries and it would still hang on the ":" after the word SHOWS of the first entry.

The weird thing is that I've copied and pasted the data returning from the PHP page and pasted it into the JavaScript function directly and it loads the Datagrid within the Flex app with no problems or errors.

I do not want to be responsible for cutting & pasting over 27,000 records on a regular basis.

So any help would be appreciated.
Mar 12 '08 #5
TheServant
1,168 Expert 1GB
I'm sure you've tried this, but what about escaping the ":"? ie. "\:"
Mar 12 '08 #6
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.  
what is $myTempVar?? all I see is your setting $myTempArray, which, in that exact code, would only show up as "Array()" to the browser.

We are either missing a vital piece of code to help you, or you are a)echoing the wrong variable and/or b) trying to echo an array which doesnt work

Im hoping that perhaps you are missing[PHP]
foreach($myTempArray as $myTempVar)[/PHP] on the line prior to your javascript echo

Oh yah, and you can probably (depending on other code in your file) remove the $count variable and set the left side on line 1 to be
[PHP]$myTempArray[] = [/PHP]
^^ this is basically the same but saves you from having to use count and increment it

wait, are you trying to append to an array key that hasn't been initialized?

do me a favor and do a [PHP]print_r($myTempArray);[/PHP] just to make sure those contents are what you expect
Mar 13 '08 #7
I also noticed that you referenced AJAX.....

if you are trying to execute Javascript through ajax you are taking the totally wrong approach. You need to have php echo the results which the AJAX function then parses and runs a function using the contents of the returned page
Mar 13 '08 #8
Yeah, I received a different error when escaping the ":" via illegal character error message.

The thing that really bothers me about all this, is that this application worked with no errors or issues before the server crashed a week and a half ago and if I cut & paste the data generated from the PHP file directly into the JS function, then it works.

I did discover something this afternoon as to where the issue is located -- between PHP and the JS file.

I know because I substituted the variable "response" for one record and it showed up in the Flex app's datagrid with no errors.

Expand|Select|Wrap|Line Numbers
  1. window.onload = eval(response);
  2. with
  3. window.onload = eval(mySeFunc([{SHOWS: "some show", GENDER: "male", AGE: "19", etc...}]));
  4.  
The problem seems to be coming from PHP echoing the data to the JS file which evaluates the string coming, once again, I manually cut & paste the one record into the PHP file and I received the error that we started with in this post.

Expand|Select|Wrap|Line Numbers
  1. echo "mySeFunc([".$myComboVar2."]);";
  2. with
  3. echo "mySeFunc([{SHOWS: "some show", GENDER: "male", AGE: "19", etc...}]);";
  4.  
And why would this same function that worked before the server crash, suddenly not work any longer?
Mar 13 '08 #9
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.  
what is $myTempVar?? all I see is your setting $myTempArray, which, in that exact code, would only show up as "Array()" to the browser.

We are either missing a vital piece of code to help you, or you are a)echoing the wrong variable and/or b) trying to echo an array which doesnt work

Im hoping that perhaps you are missing[PHP]
foreach($myTempArray as $myTempVar)[/PHP] on the line prior to your javascript echo

Oh yah, and you can probably (depending on other code in your file) remove the $count variable and set the left side on line 1 to be
[PHP]$myTempArray[] = [/PHP]
^^ this is basically the same but saves you from having to use count and increment it

wait, are you trying to append to an array key that hasn't been initialized?

do me a favor and do a [PHP]print_r($myTempArray);[/PHP] just to make sure those contents are what you expect
Sorry about the missing code for $myTempVar, but that is used just to add a comma to the end of each record until the end is reached:
Expand|Select|Wrap|Line Numbers
  1.                  for($i=0;$i<$count;$i++)
  2.                         {
  3.                              if($i<$count-1)
  4.                              {
  5.                              $myTempVar .= $myTempArray[$i].", ";
  6.                              }
  7.                              else
  8.                              {
  9.                              $myTempVar .= $myTempArray[$i];
  10.                              }
  11.                         }
  12.                         echo "javascript:mySeFunc([".$myTempVar."]);";
  13.  
Mar 13 '08 #10

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

Similar topics

5
by: Andrew | last post by:
Hi All, Have come across something weird and am after some help. Say i run this query where rec_id is a column of table arlhrl, select * from arlhrl where rec_id >= 14260 This returns to...
10
by: Tony | last post by:
I'm wondering if anyone has run any tests to compare the speed of parsing XML vs text in simple lists - such as: <?xml version="1.0" encoding="ISO-8859-1"?> <users> <user>User 1</user>...
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...
6
by: dmorand | last post by:
I'm having a little trouble with my ajax. I can see my results in IE, but not firefox. I'm assuming I'm missing some syntax somewhere. alert("Test " + results + testing); returns the values in...
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.