Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-12-2007, 11:17 PM   PM User | #1
MikoLone
Regular Coder

 
Join Date: Jun 2002
Location: Provo, UT
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
MikoLone is an unknown quantity at this point
AJAX Post Strings PHP name arrays

How would I get the same functionality of this form

Code:
<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" />
</form>
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

Code:
for(var i = 0; i < this.category.length; i++){
		 postStr += '&category%5B%5D=' + this.category[i];
	}
so the post string ends up like.

?category%5B%5D=Terminology&category%5B%5D=Medications

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?

Thanks,

Michael
__________________
I try to convince 'em that I am computer geek, but I just can't do it. Why? Oh why?
MikoLone is offline   Reply With Quote
Old 03-13-2007, 01:11 PM   PM User | #2
Ancora
Banned

 
Join Date: Oct 2005
Location: I'm in GMT -5
Posts: 314
Thanks: 0
Thanked 1 Time in 1 Post
Ancora is on a distinguished road
Code ignored. Code deleted.

Last edited by Ancora; 03-13-2007 at 07:03 PM..
Ancora is offline   Reply With Quote
Old 03-13-2007, 01:19 PM   PM User | #3
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
Ancora aka Mike H.,

STOP DOING THIS:

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.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 03-13-2007, 03:07 PM   PM User | #4
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
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.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 03-13-2007, 05:13 PM   PM User | #5
MikoLone
Regular Coder

 
Join Date: Jun 2002
Location: Provo, UT
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
MikoLone is an unknown quantity at this point
That part is no big deal anyway. I mean I have a good (I think) requester code.

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) {
				continue;
 			}
		}
	}
	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.
__________________
I try to convince 'em that I am computer geek, but I just can't do it. Why? Oh why?
MikoLone is offline   Reply With Quote
Old 03-13-2007, 06:09 PM   PM User | #6
Ancora
Banned

 
Join Date: Oct 2005
Location: I'm in GMT -5
Posts: 314
Thanks: 0
Thanked 1 Time in 1 Post
Ancora is on a distinguished road
Code ignored. Code deleted.

Last edited by Ancora; 03-13-2007 at 07:02 PM..
Ancora is offline   Reply With Quote
Old 03-13-2007, 06:45 PM   PM User | #7
MikoLone
Regular Coder

 
Join Date: Jun 2002
Location: Provo, UT
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
MikoLone is an unknown quantity at this point
OOPS!

I forgot to set the request header

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

that made it work like I wanted.

blah[]=blah1&blah[]=blah2



Sorry.
__________________
I try to convince 'em that I am computer geek, but I just can't do it. Why? Oh why?
MikoLone is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:26 AM.


Advertisement
Log in to turn off these ads.