473,399 Members | 4,177 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,399 software developers and data experts.

Getting arguments with AJAX

mikek12004
200 100+
Is it possible to put an array of values as an argument to a js function? I want through this function and with AJAX to pass this array to a PHP array inside the PHP script which will then do the rest
Jul 20 '09 #1
8 1508
acoder
16,027 Expert Mod 8TB
You could pass a string with delimiters and split on the server-side.
Jul 20 '09 #2
mikek12004
200 100+
So it is impossible to use an array eh?
Jul 20 '09 #3
acoder
16,027 Expert Mod 8TB
Well, you could use an array, but it'd be passed as a string, e.g.
[1,2,3] would be passed as "1,2,3". You could serialize it on the client-side and deserialize it on the server-side.
Jul 20 '09 #4
Canabeez
126 100+
Try something like:

Expand|Select|Wrap|Line Numbers
  1. var myPostVars = "myArray[0]=AAA&myArray[1]=BBB";
  2.  
then in PHP the $_REQUEST["myArray"] should already be a compiled array.

Expand|Select|Wrap|Line Numbers
  1. var_dump($_REQUEST["myArray"]);
  2.  
Not sure it will work, well it did in PHP3, but things have changed since then, but still worth trying. ;)
Jul 22 '09 #5
gits
5,390 Expert Mod 4TB
that suggestion shows a 'kind of serializing' a javascript array ... since you cannot use that easyly in both languages ... a very seamless way to handle more complex datatypes is to use JSON ... so that you might use simple eval() on JS-side and json_encode() or json_decode() in php ... that will do the serializing and deserializing for you ...
Jul 23 '09 #6
Canabeez
126 100+
@gits
You're right, I'd prefer building an XML in JS and then parse it in PHP, think that would be the right way to do it, or JSON as you mentioned. But the question was about passing an array through an AJAX request.
Jul 23 '09 #7
gits
5,390 Expert Mod 4TB
JSON is more lightweight compared to XML ... so i would always prefer JSON ... and the other point is: what you have suggested is a serialized array that is passed as a string ... and no array ... to be correct :)
Jul 23 '09 #8
Canabeez
126 100+
True....... True......... ;)
Jul 23 '09 #9

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

Similar topics

5
by: GaryDean | last post by:
I have a 1.1 asp.net project that has been converted by the conversion wizard. By and large the app runs allright except for one page... On one of the .aspx pages, the code behind file is not...
1
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- ...
4
by: Nathan Sokalski | last post by:
I am a beginner with AJAX, and have managed to learn how to use it when passing single parameters, but I want to return more than one value to the client-side JavaScript function that displays it....
2
by: dmagliola | last post by:
Hello all, I'm experiencing a problem with ASP.Net for which I can't find a reasonable explanation, or any information. I'm currently developing an application that, through AJAX, asks the...
6
by: Nathan Sokalski | last post by:
I am trying to start using the AjaxControlToolkit. I followed all the instructions on the following page: http://ajax.asp.net/ajaxtoolkit/Walkthrough/Setup.aspx The only thing I did...
9
by: querry | last post by:
Hi all I am new to AJAX. I am developing web application in ASP.NET C#. Please could any of you tell me how I am to go about using ajax for getting certain server values using the javascript. Please...
8
by: alejrb | last post by:
Hi! I have a pretty simple AJAX request that just GETs the content of a page depending on a name that is fed to it. I'm parsing the page in quite a complex way, so I'm using the DOM to make it a...
17
by: Scott M. | last post by:
I'd like to start working with Ajax in VS 2008 Pro., but it's important that I not use anything that is not standard with VS 2008 Pro. (with all installation options selected). Does anyone have...
18
by: vjayis | last post by:
hi i have a php page in which i have included few tabs links like games, news,entertainment etc., when i click the tablink an ajax page is loaded below. In that ajax page several...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
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,...
0
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,...
0
isladogs
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...

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.