|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Problem - Passing arrays to PHP/JS page
Hi everyone,
I've got a strange problem with an application I'm working on. The problem is around the passing of two arrays to a PHP/JavaScript page. What I'm doing is creating two arrays, one to check if the menu element is enabled, and the other to give the element a URL link. I then urlencode() and serialize() each array and pass it through a class which writes the JS script tag into the page with the URL and encoded array as variables. The JS page then does an unserialize() and stripslashes() on each array. After which I step through the array with a for loop and do some checking etc. Finally the JS page echo's the correct <span> and link to each element. Now that all works and I've done a half dozen menu's that work fine. The problem is happening when I go over 10 elements in the arrays. It's just throwing a JS error and not displaying the menu. So I was wondering if there is a limit to the size of passed arrays? I've not found anything at php.net to indicate this. Or if there is somthing else that may cause such a problem. Anyway here's the code associated with the problem broken down into the three pages. Page 1 (page that display's the menu) The commented out array elements are ones that cause the problems. As you can see there's nothing different about them it's just that it's adding an eleventh element to each array. PHP Code:
Page 2 (Class script that I use as a template) PHP Code:
Page 3 (The JavaScript page) PHP Code:
This is what I'm using to echo the spans and links in the JS page. It's strange I know but with the large size of the script all of which has to be on one line it's the only way I've found to make it echo correctly. PHP Code:
Thanks all ![]() |
|
#2
|
|||
|
|||
|
1. You don't seem to have escaped all your quotes correctly.
2. Where is the javascript? 3. Have you checked (by printing to the screen) that the serialized strings are the same on each page? This would check that it's a problem with your code rather than the strings being truncated. Hadley |
|
#3
|
|||
|
|||
|
Thanks for replying Hadley,
The code I actually have in the array looks like this: $itemURL2[] = "<a href=\\\"../projects/viewproject.php?display=projectdetails&id=$id&$transmitSid\\\" $linkStyle>";//Details I just realised that putting it in the php forum tags kind of messes with it. Strange with so many slashes but it works ![]() Anyhow I've found out that the problem is the length of the URL string. I've tested it own two blank pages that just pass arrays. I can get to a total of 26 elements before it won’t allow breaks down and won’t allow the page to progress. So my problem at the moment is that I need to send 100 variables between pages, whilst keeping it an acceptable length. If anyone has any ideas I would love to hear them ![]() I'm looking at doing some checks inside the php in the JS file instead of passing variables. I hope that will work okay. |
|
#4
|
|||
|
|||
|
Hmmm. Strange, I didn't think URL strings had any practical limit.
You might want to think about passing the data around some other way: using forms and POST, through a text file or database. Hadley |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Problem - Passing arrays to PHP/JS page |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|