By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

passing array to php from Ajax

omerbutt
100+
P: 638
hi
i have an html input which is built from php and have an onclick function that calls the javascript function and sends some arrays to that function which are initialized via php and then passed to javascript function and then again submitted to a php file via an AJAX call but the problem is that when passed to the php file via AJAX it try to echo those arrays , they show me the following rather than the values
Expand|Select|Wrap|Line Numbers
  1. <pre>function Array() {
  2.     [native code]
  3. }</pre></pre>function Array() {
  4.     [native code]
  5. }<pre>function Array() {
  6.     [native code]
  7. }</pre>
  8.  

here is the js function

Expand|Select|Wrap|Line Numbers
  1. var xmlGuestInfo=null;
  2.     function getGuestInfo(mbr,id,t_days,type,t_guests,t_stays,all_dates,unique_dates,guest_beds_arranged){
  3.         var guest_name    =    document.getElementById("guest_name_"+id).value;
  4.         if(mbr=="" && guest_name==""){
  5.             displayError("Please Enter Guest Name to proceed.");
  6.             if(document.getElementById("guest_price_"+id).value!=''){
  7.                 document.getElementById("total_price").value=document.getElementById("total_price").value.substr(0,parseFloat(document.getElementById("total_price").value.length) - parseFloat(1))-parseFloat(document.getElementById("guest_price_"+id).value.substr(0,parseFloat(document.getElementById("guest_price_"+id).value.length) - parseFloat(1)))+"$";
  8.                 document.getElementById("guest_price_"+id).value='';
  9.             }
  10.         }else{
  11.             if(guest_name=="" && type=="MBR"){
  12.                 displayError("Please enter guest name before entering the MBR#");
  13.             }else if(guest_name=="" && type=="GST"){
  14.                 displayError("Please enter guest name");
  15.             }else{
  16.                 var str=encodeURI("guest_name="+guest_name+"&member_id="+mbr+"&t_days="+t_days+"&row_id="+id+"&t_guests="+t_guests+"&t_stays="+t_stays+"&all_dates="+all_dates+"&unique_dates="+unique_dates+"&guest_beds_arranged="+guest_beds_arranged);
  17.                 var url="index.php?option=com_reservations&task=checkMember&format=raw&"+str;
  18.                 xmlGuestInfo=GetXmlHttpObject();
  19.                 if(xmlGuestInfo==null){
  20.                     alert("Please upgrade your browser");
  21.                     return;
  22.                 }else{
  23.                     xmlGuestInfo.onreadystatechange=$getGuestInfo;
  24.                     xmlGuestInfo.open("GET",url,true);
  25.                     xmlGuestInfo.send(null);
  26.                 }
  27.             }
  28.         }
  29.  
  30.     }
  31. function $getGuestInfo(){
  32.         if(xmlGuestInfo.readyState==4){
  33.             if(xmlGuestInfo.status==200){
  34.                 alert(xmlGuestInfo.responseText);
  35.                 return;
  36.             }
  37.         }
  38.  
  39.     }
  40.  
Nov 1 '11 #1

✓ answered by omerbutt

that was not the problem :) , but solved anyhow
thanks
,
Omer Aslam

Share this Question
Share on Google+
2 Replies


100+
P: 1,059
here is an example of how to send an array of data

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     print_r($_GET);
  3. ?>
  4. <FORM action=''>
  5. <input name='pp[]'>
  6. <input name='pp[]'>
  7. <input name='pp[]'>
  8. <input type='submit'>
  9. </FORM>
  10.  
Nov 3 '11 #2

omerbutt
100+
P: 638
that was not the problem :) , but solved anyhow
thanks
,
Omer Aslam
Nov 10 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.