|
Hi,
I am looking for an easy way to transfer a javascript array from one page to another. The page that it is being transferred to will be either POSTed or GETted (hmm, that didn't quite work how I wanted it to) from the previous page.
One way that I have thought of is converting it to a string and sending it over GET, and I found this[^], but I have a few concerns with it. It is firstly a two dimensional array, so I would need to convert that to a string and then convert it back at the other end, the second is security (if it is sent over GET, even on an SSL connection, URL will probably still be visible to someone eves dropping), and third is length (the string could get very long very quickly, and there could become problems if the URL gets too long and messy). That said, I could also devise a way using a hidden form object to send it over POST, so I would probably end up doing it that way.
My question is basically, should I convert it to a string and then parse it back into an array later on, or is there an easier way that I am missing?
Thanks heaps, Josh.
|
|
|
|
|
if security is an issue you can use encryption to encrypt the array. you could look into using AJAX post as well. jQuery is an excellent extension for helping with this and great for beginnners (those who havent delt with creating httprequests before).
I know in PHP you can serialize the array - so maybe there's an equivalent function in javascript?
|
|
|
|
|
Thanks for the reply.
What I am doing as a solution is turning the array into one long string, using AJAX to store it in a PHP session, moving to another page and then having PHP process it when it restores the session.
Basically, the code I am using to turn the array into a string is:
function convertTwoDimensionArrayToString(arrayToConvert) {
arrayAsString = "7"
for (i in arrayToConvert) {
for (j in arrayToConvert[i]) {
arrayAsString += "%%" + arrayToConvert[i][j];
}
}
return arrayAsString;
}
Because it is a two dimensional array, I need to run the for loop twice, but that said, it will put everything into one long, string (obviously). To turn it back into a two dimensional array, I have used the first index (0) to define the array length so the second dimension in every array in this case has a length of 7. I don't know if I explained my logic that well, but it makes sense to me
This will ONLY work if the second dimension in the array is always the same length (and in my case, it ALWAYS will be, there would be a major flaw in the program if there wasn't). If the second dimension in the array varies in length, I would change the code to separate the different index's of the second array differently to how I would separate the different index's of the first array.
It definitely does work (and it gives me a way to get the array from javascript to php without too problems as well!), but it isn't the most elegant solution. Just thought I would share my solution with others!
|
|
|
|
|
You could send the items of data individually using AJAX if, for example, it is entered into a form and have PHP convert it into the array.
Also, if the amount of data is too long you could encrypt it and store it as an encrypted cookie - so long as it doesn't affect usability if the cookie is deleted (You can pass cookies between javascript and PHP).
Joshua Henderson wrote:
It definitely does work (and it gives me a way to get the array from javascript to php without too problems as well!), but it isn't the most elegant solution.
Depends on you definition of "elegant solution", development speed or short fancy code. Your code looks fine to me anyway. Clean, readable and concise.
|
|
|
|
|
Hi,
I have a web based application writing with asp.net and vb.net,it sends and recieves requests between users and helpdesks,I want check the database and if a new request has already been added to database, show an alert to the helpdesk,I think I should use a conditional update panel and set a timer in that and check for incoming request,but I dont know how to show alert after that!!!
I will be thankfull if anybody could help me..
with regards
modified on Tuesday, August 18, 2009 10:03 AM
|
|
|
|
|
hi all
all what i want to do is to show a confirmation message the user when he try to close the page, if he want to close the page i have some code to execute, but if he decide to stay i want to keep the window open.
i used the following function but it have one issue: when the user click cancel the page get closed
so can you help me and tell what i did wrong
am using IE7
window.onbeforeunload = HandleOnClose;
function HandleOnClose(event)
{
if(currentElement == "" || (!(currentElement.getAttribute("tag")=="DonotCallSaveonLoad")))
{
if(divTimer.style.display != 'none')
{
var objWarningMsg = document.getElementById("<%=hdnCloseWOWarning.ClientID %>").value;
if(objWarningMsg == "False")
{
var objconfirm = confirm("you wont be able to open this quiz again, continue?")
if(objconfirm == true)
{
FunctiontoCallSaveData();
}
else
{
}
}
else
{
FunctiontoCallSaveData();
}
}
else
{
FunctiontoCallSaveData();
}
}
}
|
|
|
|
|
if(objconfirm == true){
FunctiontoCallSaveData();
} else {
return false;
}
I think
|
|
|
|
|
thank but not working
all what it did it gave me another popup with ok and cancel
this should work with normal end users but mine are way below that level
|
|
|
|
|
|
Hi!
The code:
window.onbeforeunload = function () {
var conf = window.confirm ("Are you sure you want to navigate away from this page?");
if (conf) {
return false;
} else {
return true;
}
}
Visit this page to get more information about
onbeforeunload event.
|
|
|
|
|
Hello, I am trying to access HTML DOM elements in a remote window using JavaScript and getElementsByTagName but the resultant arrays are undefined.
<pre>
var remoteWin = window.open(URL,'rmtWindow');
remoteTags = remoteWin.document.getElementsByTagName("<tag>");
localTags = self.document.getElementsByTagName("<tag>");
</pre>
This works fine for localTags but not for remoteTags.
Am I not referencing the remote window correctly?
Also there seems to be some inconsistency in returned values:
<pre>
<a href="href URI string" param="hvalue"><img src="img URI string" param="ivalue"></a>
getElementsByTagName("a") returns the full "href URI string" string but getElementsByTagName("img") returns "[object HTMLImageElement]"
</pre>
I want to retrieve and manipulate the actual text strings of these elements, i.e., I want to access "img URI string", "hvalue" and "ivalue". I assume that I need to access properties of "[object HTMLImageElement]" to obtain the strings, including the strings for the optional parameter strings, but where or how do I find the definition of these properties?
Is there a way to associate the returned value for each embedded "img" element with its encapsulating "a" element? It is highly unlikely that the array indicies will match.
[Edit] Is the "img" element a child of the "a" element? If so I can associate them that way.
Thank you for your help, Art
[Edit] Firefox did not complain about this code, just left the values "undefined".
Opera [9.6], throws an exception and says "Security error: attempted to read protected variable".
Yet neither gives me any trouble when I write to a remote window. What's going on???
modified on Tuesday, August 18, 2009 4:56 AM
|
|
|
|
|
Hello,
I am part of a Volunteer Fire Department and have been tasked with coming up with a way to train the members how to properly use their two way radios on the fire scene.
To do this I would like to create a website that shoots out a Scenario to a member sitting in front of the computer with a radio in hand, He must communicate to another member sitting at another computer viewing the same training site. Once the second member receives the message over the radio he would click on a button on the site that would register what message was received and the "Trainer" can score if it was a correct transmitting by what the receiving operator clicked.
This is just a basic explanation of what I want done, I slightly knowledgeable in PHP and HTML but would need some help in designing something like this, I believe storing the information in a database would be the best bet.
Therefore I am looking for someone who is interested in helping the Fire Department to build this web tool.
Please let me know if you are interested in helping with this project, or provide any helpful feedback on the best approach to this project.
Thank You.
|
|
|
|
|
Depending where you are located, you might want to contact your local universty and find out if their computer science department supports "Senior Projects", where a team of senior computer science majors are assigned to you to solve your problem. They are graded on the completed project. Cool idea. The students get a chance to solve a real-world problem and you get a system built for free !
Just an idea ...
|
|
|
|
|
Good Idea but the closest university is about an an hour away and they don't have any web courses or anything offered.
|
|
|
|
|
When it comes to making websites the designers can be on the other side of the world to their client - often the two never meet - I agree that a university option would be your best bet for a free site. you could also ask around for friends of friends that are web designers who may be able to give you a basic mates rates site.
|
|
|
|
|
I'm trying to get an ejb timer to work. I really don't why its doing this but any help will due.
Here is the code:
package session.TimerBean;
import javax.annotation.Resource;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class Timers implements TimerLocal{
@Resource
private SessionContext roe;
private TimerService ts;
public Timers() {
}
public void TimerB()
{
<big>Timer time = ts.createTimer(6000, null);</big>
System.out.println("checking");
}
@Timeout
public void WorkingTimer(Timer time)
{
System.out.println("Timer Bean is working!!!!");
}
}
And here is the error:
Exception in thread "main" java.lang.NullPointerException
at session.TimerBean.Timers.TimerB(Timers.java:33)
at client.session.TimerBean.Client.main(Client.java:12)
Line 33 is in big font.
|
|
|
|
|
hello all,
i want to edit my more than 10000 html pages. all pages are online.
i want to add one script for each page.
how can i do it.
please help me.
Thanks in advance.
Regards
Praveen
|
|
|
|
|
download them locally, then use a find and replace..?
|
|
|
|
|
thanks for ur reply.
but it is very hard task.
i am looking something some kind of programming for it.
|
|
|
|
|
Replace your
</head> with
<script>
your script
</script>
</head>
There is an option in dreamweaver or many editors to replace text of all files in a particular folder.
Hope this will help.
|
|
|
|
|
thanks Anurag for ur suggestion.
but if i want change the table structure of all html files inside the folder, it is possible using dreamweaver or editor.
thnaks in advance
|
|
|
|
|
u can see the example here
http://www.advance-international.com/
i need to display the time,temperature,weather country wise and when the time is being displayed i need the the next country time to be displayed after 30 secs.is it possible
something like a scrolldelay.
pls help
|
|
|
|
|
use set interval and innerhtml - JavaScript
|
|
|
|
|
hi sir
i want an javascript for my newsticker in which information is move verticlly up.when i have cursor on that newticker then information should stop and on removing from there the information should move again.and one more thing i want to add that if i move my cursor up on newsticker then information should go down and if cursor go down then information should go up.
please help me.
|
|
|
|
|
onmouseover="TICKER_PAUSED=true" onmouseout="TICKER_PAUSED=false"
|
|
|
|