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[$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++;
-
-
echo "javascript:mySeFunc([".$myTempVar."]);";
-
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 :-)
9 1324
Can you post an example array that shows up this error.
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
Where is this piece of code being echoed?
-
echo "javascript:mySeFunc([".$myTempVar."]);";
-
From there the javascript file takes the echo: -
window.onload = eval(response);
-
Which calls the function to send the array to a datagrid within a Flex app: -
function mySeFunc(someArrayComing)
-
{
-
var flexApp = FABridge.fab.root();
-
flexApp.myActionScriptFromJavascript(someArrayComing);
-
}
-
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 ":"?
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?
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(): -
var phpscript2 = '../../two_arrays_into_one.php';
-
-
function createRequestObject()
-
{
-
var req;
-
-
if(window.XMLHttpRequest)
-
{
-
// Firefox, Safari, Opera...
-
req = new XMLHttpRequest();
-
}
-
else if(window.ActiveXObject)
-
{
-
// Internet Explorer 5+
-
req = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
else
-
{
-
// There is an error creating the object,
-
// just as an old browser is being used.
-
alert('There was a problem creating the XMLHttpRequest object');
-
}
-
return req;
-
}
-
-
// Make the XMLHttpRequest object
-
var http = createRequestObject();
-
-
function sendRequestPost2()
-
{
-
// Open PHP script for requests
-
http.open('post', phpscript2);
-
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
-
http.onreadystatechange = handleResponsePost;
-
http.send('userid=1');
-
//window.onload = eval('javascript:writeMyHtmlFunction('+session+','+id+');');
-
}
-
-
-
function handleResponsePost()
-
{
-
if(http.readyState == 1)
-
{
-
document.getElementById("response2").innerHTML = "Please wait, loading... " ;
-
}
-
else if(http.readyState == 4 && http.status == 200)
-
{
-
-
// Text returned from PHP script
-
var response = http.responseText;
-
-
if(response)
-
{
-
// document.getElementById("response2").innerHTML = response;
-
window.onload = eval(response);
-
// mySeFunc();
-
}
-
}
-
}
-
-
The function of course calls the PHP file which logs into the database, retrieves the data and then returns the values via the echo: -
echo "javascript:mySeFunc([".$myTempVar."]);";
-
The echo is then called to action via the JS file: -
window.onload = eval(response);
-
Which the JS code for the mySeFunc is as follows: -
function mySeFunc(someArrayComing)
-
{
-
var flexApp = FABridge.fab.root();
-
flexApp.myActionScriptFromJavascript(someArrayComing);
-
}
-
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 -- -
echo "javascript:mySeFunc([".$myTempVar."]);";
-
-
and JS:
-
-
window.onload = eval(response);
-
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: -
// document.getElementById("response2").innerHTML = response;
-
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
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.
Actually, mySeFunc does return a function to the Flex application and populates the datagrid with the info within the param being passed: -
function mySeFunc(someArrayComing)
-
{
-
var flexApp = FABridge.fab.root();
-
flexApp.myActionScriptFromJavascript(someArrayComing);
-
}
-
Here is the myActionScriptFromJavascript function within the Flex app: -
public function myActionScriptFromJavascript(someArrayComing:Array):void
-
{
-
dataGrid.dataProvider = someArrayComing;
-
dataGrid.validateNow();
-
}
-
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: -
echo "javascript:mySeFunc([".$myTempVar."]);";
-
-
and
-
-
window.onload = eval(response);
-
And why did this work for months, then die a couple of weeks ago.
Thanks in advance
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 .=...
|
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...
|
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
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |