Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

  • #2
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Code ignored. Code deleted.
    Last edited by Ancora; 03-13-2007 at 08:03 PM.

  • #3
    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
    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]

  • #4
    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
    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]

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Code ignored. Code deleted.
    Last edited by Ancora; 03-13-2007 at 08:02 PM.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •