AJAX

Moderators: None (Apply to moderate this forum)
Number of threads: 60
Number of posts: 100

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Ajax + php passing parameter as array Posted by ierpe on 24 Sept 2008 at 6:13 AM
I am building a web application in Ajax + Php.
Using Ajax, i would like to pass a javascript array containing some form values to a php script.
The script php then should get the array and access the array data.
But I cant get it working :p
I think I am doing something wrong in my js function...

Here is my form:
<script>var p = new Array()</script>
<form>
<b>Search Content:</b> <input type="text" name="p[]" onkeyup="control(p,'content_get2')">

<b>in</b>
<select name="p[]">
 <? $misc->getSelectCategory(); ?> //fetch data in the db and build the select list
</select>
</form>


Here is my control function in my ajax.js
function control(p,action)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url= "include/"+ action +".php"
url=url+"?p[]="+p
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}


And in my content_get2.php: $p = $_GET["p"];
Since I send my url+"?p[]="+p, i get an array, but its empty...
What do i do wrong?

Please help me!
Report
Re: Ajax + php passing parameter as array Posted by Falkon303 on 6 Oct 2009 at 12:08 PM
I recommend http://script.aculo.us/downloads for ajax requests

usage is much easier

function request()
{new Ajax.Request('usethesamepage.php', { method: 'get', parameters: { req: $('formname').serialize()}, onSuccess: function(p)  
{alert(p.responseText);}})}




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.