/    Sign up×
Community /Pin to ProfileBookmark

new to xmlhttprequest, how to access the query string

Hi I’m new to xmlhttprequest and am not sure if this should go in the javascript section or php section.

I’ve got my xmlhttprequest working with POST as the method.

xmlhttp.send(queryString);

and my string looks like this

indentifyer1=object1&indentifyer2=object2&indentifyer3=object3& so on..

I can then access my string in PHP like this:

[code=php]$var1 = $_POST[‘identifyer1’];
$var2 = $_POST[‘identifyer2’];
$var3 = $_POST[‘identifyer3’];
//and so on…
echo $var1;
// which gives me – object1[/code]

Problem is If the string is put together based on user input then I don’t have any way of knowing how long the string is and how many objects are in it and how many $vars to set up.
Normally I would set up a for loop in php based on the length of an array etc but can’t do that here. Is there anyway to better identify the length of the string in PHP or is there a better way to format the queryString in Javascript?

thanks fo any help.

Chris?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@LeeUAug 06.2008 — Please do not cross post. The other thread has been removed.
Copy linkTweet thisAlerts:
@cannon303authorAug 06.2008 — yes thanks for that, I did think that it was better suited in the javascript forum rather than the php one so never mind.

It was a real question and I didn't and still don't know where to post it and now I'm probably not going to get my question answered here so yes thanks very much for that indeed!
Copy linkTweet thisAlerts:
@SyCoAug 06.2008 — Why rename POST vars? Why not just use the POST vars as is.

What's the problem with looping through the POST array? You if you're looking for specific fields you can look at the key for a particular pattern eg 'identifyer'

Why do you think PHP questions are better suited in the jS forum and why be sarcastic to the admin. He sets the rules. Plenty of other forums out there (they have the same cross posting rule usually though).
Copy linkTweet thisAlerts:
@cannon303authorAug 08.2008 — Why rename POST vars? Why not just use the POST vars as is.

What's the problem with looping through the POST array? You if you're looking for specific fields you can look at the key for a particular pattern eg 'identifyer'

Why do you think PHP questions are better suited in the jS forum and why be sarcastic to the admin. He sets the rules. Plenty of other forums out there (they have the same cross posting rule usually though).[/QUOTE]



I don't think that php questions are better suited in js.

I didn't know where i could make improvements to my work, either in the js or the PHP as they are working together. My hunch was that i could perhaps make improvements in my js rather than php but I didn't know at the time, that's why i cross posted.

I can't identify the variables if I don't know how many there are as i stated previously - they are user defined

Oh and I wasn't being sarcastic. It would have been nice if the administrator had bothered to read my post and based on the nature of the thread - exercised a little discretion as was the case in another forum where administrators and posters were only too happy to help and indeed gave me the answer.
Copy linkTweet thisAlerts:
@SyCoAug 08.2008 — Glad you found the answer, care to share it here?
Copy linkTweet thisAlerts:
@LeeUAug 08.2008 — I moved it here because you had already received an answer and, instead of combing ..... etc., this was easier. If you're not getting an answer, you can always notify the admin/mod and they can either move it or close it and you can open another one.

Just trying to be helpful .............
Copy linkTweet thisAlerts:
@cannon303authorAug 15.2008 — the answer was quite obvious really. you use javascript to count the variables before sending and then add that to the query string: &vLength=10. you can then use that in php to measure how many times to loop through the variables.
×

Success!

Help @cannon303 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...