View Full Version : AJAX Post Strings PHP name arrays

03-13-2007, 12:17 AM
How would I get the same functionality of this form

<form action="Pronunciation.php" method="POST">
<div><label><input type="checkbox" name="category[]" value="Medications" />Medications</label></div>
<div><label><input type="checkbox" name="category[]" value="Terminology" />Terminology</label></div>

<div><input type="text" name="t" />Search Text</div>
<input type="submit" value="submit" />

using ajax.

How would I write the post string in such a way that I can get an category array post to the php file.

I have

for(var i = 0; i < this.category.length; i++){
postStr += '&category%5B%5D=' + this.category[i];

so the post string ends up like.


but in the php file it says that category is not set.

Any ideas or alternatives to getting the array of categories to my php file using ajax?



03-13-2007, 02:11 PM
Code ignored. Code deleted.

03-13-2007, 02:19 PM
Ancora aka Mike H.,


var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();

You are spreading very bad code. Please stop being fancy and use try catch. There are reasons why people are doing it that way! First IE7 uses Native Object. If ActiveX is disabled and you access the XMLHttp, it throws an error!

If you work in production environments with High Traffic and clientside error logging, you would know that is wrong in every way.


03-13-2007, 04:07 PM
Sorry you feel that way. Not sure why you would have to respond in such a manner. I was just telling you that what you are doing will cause errors on people's machines that have ActiveX disabled.

I do research in this area and I know what problems area are. That is one of them.


03-13-2007, 06:13 PM
That part is no big deal anyway. I mean I have a good (I think) requester code.

function getXMLHTTPRequest() {
var requester = false;
try {
requester = new XMLHttpRequest();
catch (error) {
var aVersions = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHTTP"];
for(var i = 0; i< aVersions.length;i++){
try {
requester = new ActiveXObject(aVersions[i]);
catch (error) {
return requester;

Where I have done some research also and hopefully have a good function going but what I would like is to build not only a post string but a post string that contains an array. Just like when you name a form element name="blah[]". If you do that to multiple elements the post will contain an array called blah. I would like to write a post string that builds an array like that for me. Is it possible?

Thanks for responding.

03-13-2007, 07:09 PM
Code ignored. Code deleted.

03-13-2007, 07:45 PM

I forgot to set the request header

oHTTPPronounceReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

that made it work like I wanted.