473,378 Members | 1,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

omerbutt
638 512MB
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
9 6748
Dormilich
8,658 Expert Mod 8TB
have you checked, whether the data are in any of the other superglobal arrays ($_GET, $_REQUEST, etc.)?

Im not sure about IE10s dev tools, but maybe you can find anything there about the issued network traffic.
Apr 16 '13 #2
omerbutt
638 512MB
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
8,658 Expert Mod 8TB
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
638 512MB
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
8,658 Expert Mod 8TB
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
8,658 Expert Mod 8TB
interseting read: sending AJAX with form data directly (https://developer.mozilla.org/en-US/...rmData_Objects)
Apr 17 '13 #7
omerbutt
638 512MB
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
638 512MB
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
8,658 Expert Mod 8TB
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

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

Similar topics

13
by: Marcus | last post by:
Hi All, I was wondering if there is a way to ensure that when submitting forms and using POST vars, the page sending the form resides on the same server as the destination page specified in the...
5
by: Kit | last post by:
Hi there, I am recoding a website, and I want to add a generic footer to each page, using an included file with PHP snippets. Part of that footer would be a link to validate the page using the...
3
by: Vic Spainhower | last post by:
Hello, I have an HTML table that is being constructed from a MySQL table and displays a form that includes a check box on 1 of the fields on the form for each record. I have included in this PHP...
2
by: Aaron | last post by:
I'm trying to pull data from a website and read it into a file the I can parse. I've done the before to site without post variables but I can seem to get my statments to work with the post. Can...
17
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
5
by: steve.chambers | last post by:
I'm sure this q must have been asked before but I'm really struggling to find the answer anywhere so have finally given up and will consult the usenet community - hopefully there's someone out...
3
by: dhsieh | last post by:
I am trying out nested AJAX calls for the first time, but I seem to have hit a snag. The code snippet is the outer AJAX call and a function, it gathers information about a company. As we get towards...
7
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
我们现在遇到一个问题,通过wcf创建的webservice,选择windows service作为宿主,采用java作为客户端调用成功,但是无法使用asp.net ajax调用。...
1
by: kidalex | last post by:
So, I have a summary page of some stuff that gets updated through AJAX calls back to the server every 15 seconds or so. However, if you leave that page up for a few hours - it'll slow down the...
1
by: andwan0 | last post by:
I have a legacy classic ASP website with lots of classic AJAX (many ASP files specially made for processing AJAX requests). We are slowly migrating the website to ASP.NET 2.0 and developing under...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.