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

IE10 doesn't post variables in post array with Ajax calls

omerbutt
100+
P: 638
Hi i am working on a module and my code is working fine on all browser except when using IE10 my ajax requests does not post data inthe $_POST array here is my javascript code
Expand|Select|Wrap|Line Numbers
  1. var objXMLHttp;
  2.  
  3. function GetXmlHttpObject(){
  4.     objXMLHttp=null;
  5.     try{
  6.         // Firefox, Opera 8.0+, Safari
  7.         objXMLHttp=new XMLHttpRequest();
  8.     }catch (e){
  9.         // Internet Explorer
  10.         try{
  11.             objXMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
  12.         }
  13.         catch (e){
  14.             try{
  15.                 objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  16.             }
  17.             catch (e){
  18.                 jAlert('Please upgrade your browser','<span>No AJAX Support</span>');
  19.                 return false;
  20.             }
  21.         }
  22.     }
  23.     return objXMLHttp;
  24. }
  25. var xmlCheckoutExb;
  26.     function checkout_exhibitor(){
  27.         var str=getFormsExb();
  28.         str=str+'&num='+Math.floor(Math.random()*1);
  29.         var url=base_url+"exhibitor/save_conference_registration";
  30.         xmlCheckoutExb=GetXmlHttpObject();
  31.         if(xmlCheckoutExb==null){
  32.             alert("Please upgrade your browser");
  33.             return;
  34.         }else{
  35.             xmlCheckoutExb.onreadystatechange=$checkout_exhibitor;
  36.             xmlCheckoutExb.open("POST",url,true);
  37.             xmlCheckoutExb.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  38.             xmlCheckoutExb.setRequestHeader("Content-length", str.length.toString());
  39.             xmlCheckoutExb.setRequestHeader("Connection", "close");
  40.             xmlCheckoutExb.send(str);
  41.         }
  42.     }
  43.     function $checkout_exhibitor(){
  44.         if(xmlCheckoutExb.readyState==4){
  45.             alert('4');
  46.             if(xmlCheckoutExb.status==200){
  47.                 alert('200');
  48.                 var responses=xmlCheckoutExb.responseText.split("|");
  49.                 var switching_option='';
  50.  
  51.                 var str            =    responses[1];
  52.                 var status        =    responses[0];
  53.                 var insert_id    =    responses[2];
  54.  
  55.                  switching_option=jQuery("#payment_optins_div :checked").val();
  56.  
  57.                 if(status=="Done"){
  58.                     if(switching_option=='paypal'){
  59.                         location.replace("https://www.sandbox.paypal.com/cgi-bin/webscr"+"?"+str);
  60.                     }else{
  61.                         /*TOUQEER USE THIS PORTION*/
  62.                         window.location = base_url+"exhibitor/order_pdf/"+insert_id;
  63.                     }
  64.                 }else{
  65.                     alert(xmlCheckoutExb.responseText);
  66.                 }
  67.             }
  68.         }
  69.     }
  70.     function getFormsExb(){
  71.         var fobj=document.forms["registration"];
  72.         var str="";
  73.         var cmd="";
  74.         var val="";
  75.  
  76.         for(var i=0; i<=fobj.elements.length-1;i++){
  77.             switch(fobj.elements[i].type){
  78.                 case "text":
  79.                         if(fobj.elements[i].value!=''){
  80.                         str += fobj.elements[i].id + "=" + fobj.elements[i].value + "&";
  81.                         }
  82.                 break;
  83.  
  84.                 case "hidden":
  85.                     str += fobj.elements[i].id + "=" + fobj.elements[i].value + "&";
  86.                 break;
  87.  
  88.                 case "radio":
  89.                     if(fobj.elements[i].checked){
  90.                         str += fobj.elements[i].id + "=" + fobj.elements[i].value+ "&";
  91.                     }
  92.                 break;
  93.  
  94.                 case "checkbox":
  95.                     if(fobj.elements[i].checked){
  96.                         str += fobj.elements[i].name + "=" + fobj.elements[i].value+ "&";
  97.                     }
  98.                 break;
  99.                 case "textarea":
  100.                     if(fobj.elements[i].value!=''){
  101.                         str += fobj.elements[i].name + "=" + fobj.elements[i].value + "&";
  102.                     }
  103.                 break;
  104.             }
  105.         }
  106.         str = str.substr(0,(str.length - 1));
  107.         return encodeURI(str);
  108.     }
  109.  
when i alert the post array on the php page which i am calling in the ajax call it simply shows empty array , can any one help.
regards,
Omer Aslam
Apr 16 '13 #1
Share this Question
Share on Google+
9 Replies


Dormilich
Expert Mod 5K+
P: 8,639
have you checked, whether the data are in any of the other superglobal arrays ($_GET, $_REQUEST, etc.)?

Iím not sure about IE10ís dev tools, but maybe you can find anything there about the issued network traffic.
Apr 16 '13 #2

omerbutt
100+
P: 638
yes i have checked it if turn the request to GET and pass null in xmlRequestObject.send() then the data is passed into the GET array and is visible, i used the developer tools but it didnt showed any error through which i cold backtrack the problem there are several people facing the issue when i googled it
regards,
Omer Aslam
Apr 16 '13 #3

Dormilich
Expert Mod 5K+
P: 8,639
have you changed the Content-Type header for the POST request accordingly?

I meant the dev tools to check, what exactly you send an receive.
Apr 16 '13 #4

omerbutt
100+
P: 638
i collect all the fields via javascript using
Expand|Select|Wrap|Line Numbers
  1. getFormsExb() 
  2.  
which returns a concatenated string of the field's values and names which is then sent to the php page via AJAX call using method POST and passing the string in xmlHttp.send(str);
when i start monitoring the traffic on the IE dev tool it shows me nothing in the request body although i try to alert the string that is about to be posted via ajax and it has all the values available , i temporarily changed the method from POST to get and changed the php code to GET to make it work but POST isnt working yet still trying to figure out
here is the detail for the network capturing tab
REQUEST HEADERS
Key Value
Request POST /content/save_conference_registration HTTP/1.1
Accept */*
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Referer http://www.wcpa.nxb/content/annual_conference
Accept-Language en-US
Accept-Encoding gzip, deflate
User-Agent Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)
Host www.wcpa.nxb
Content-Length 0
DNT 1
Connection Keep-Alive
Cache-Control no-cache
Cookie PHPSESSID=7r19l8de9elbdmqmm9su6dquu6
REQUEST BODY
NO DATA TO VIEW
RESPONSE HEADERS
Key Value
Response HTTP/1.1 200 OK
Date Wed, 17 Apr 2013 08:29:14 GMT
Server Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By PHP/5.3.8
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma no-cache
Content-Length 10
Keep-Alive timeout=5, max=82
Connection Keep-Alive
Content-Type text/html
RESPONSE BODY
Array
(
)
INITIATOR
Property Value
Stage Document Processing
Element XMLHttpRequest
Action Processing
Document ID 0
Frame ID 0
Frame URL http://www.wcpa.nxb/content/annual_conference
Apr 17 '13 #5

Dormilich
Expert Mod 5K+
P: 8,639
when i start monitoring the traffic on the IE dev tool it shows me nothing in the request body although i try to alert the string that is about to be posted via ajax and it has all the values available
at least we know now that the problem is not withing PHP, but within IE.
Apr 17 '13 #6

Dormilich
Expert Mod 5K+
P: 8,639
interseting read: sending AJAX with form data directly (https://developer.mozilla.org/en-US/...rmData_Objects)
Apr 17 '13 #7

omerbutt
100+
P: 638
sorry dormilich but i could not get anything here that could help me out still wandering around and not getting to the real cause....changing everthing to GET starts working but not with POST.
regards,
Omer Aslam
Apr 18 '13 #8

omerbutt
100+
P: 638
aah i figured out the main part which had the problem it was the main function through which i was generating the new xmlHtttpObject
Expand|Select|Wrap|Line Numbers
  1. function GetXmlHttpObject(){
  2.  objXMLHttp=null;
  3.     try{
  4.         // Firefox, Opera 8.0+, Safari
  5.         objXMLHttp=new XMLHttpRequest();
  6.     }catch (e){
  7.         // Internet Explorer
  8.         try{
  9.             objXMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
  10.         }
  11.         catch (e){
  12.             try{
  13.                 objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  14.             }
  15.             catch (e){
  16.                 jAlert('Please upgrade your browser','<span>No AJAX Support</span>');
  17.                 return false;
  18.             }
  19.         }
  20.     }
  21.     return objXMLHttp;
  22. }
  23.  
i replaced this old style try catch to the following
Expand|Select|Wrap|Line Numbers
  1. function GetXmlHttpObject(){
  2.     var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
  3.     if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  4.         for (var i=0; i<activexmodes.length; i++){
  5.             try{
  6.                 return new ActiveXObject(activexmodes[i])
  7.             }
  8.             catch(e){
  9.             //suppress error
  10.             }
  11.         }
  12.     }else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  13.         return new XMLHttpRequest()
  14.     else
  15.         return false
  16. }
  17.  
and everything started working perfect :D, i still cant figure out after comparing the 2 methods that what could be the thing that was causing not to pass the data through POST method.
regards,
Omer Aslam
Apr 18 '13 #9

Dormilich
Expert Mod 5K+
P: 8,639
i still cant figure out after comparing the 2 methods that what could be the thing that was causing not to pass the data through POST method.
then the first question would be, which object (ActiveX, XHR) your browser did use. And we all know that an implemented object does not necessarily be error free.
Apr 20 '13 #10

Post your reply

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