473,412 Members | 2,048 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,412 software developers and data experts.

XMLHttpResponse is not showing any response....

rpnew
188 100+
Hi All,

I'm working on one project in which i'm using PHP/MySql. And somewhere i'm using AJAX... XMLHttpResponse......... it works fine everywhere but when somewhere i dont know why it is not showing any response.....

One more thing to debug this i'm using FireBug for FireFox it shows that URL i'm sending is created with proper variable but dosent show anything in HEADER tab and in RESPONSE tab it is showing "Loading...." ....and more strange thing is... it was working fine just a five min before and without changing anyhing i tried it again after 5 min (may be less than that even) and it stopped working....

Yeah i like to mention one more thing here is i'm using XMLHttpResponse object in for loop here... so does it creating any problem??? if you want i can post the code here as well.....

Regards,
RP
Dec 13 '07 #1
31 6862
gits
5,390 Expert Mod 4TB
hi ...

yes we want :) ... please post the code that makes the problems ...

kind regards
Dec 13 '07 #2
rpnew
188 100+
hi gits..
following is the Ajax Code....

Expand|Select|Wrap|Line Numbers
  1. function confirm_use()
  2.     {
  3.         var tbl=document.getElementById("ctypedelete");
  4.         for(i=0;i<tbl.tBodies[0].rows.length-1;i++)
  5.         {
  6.             var cBox=document.getElementsByName('compt[]')[i];
  7.             if(cBox.checked)
  8.             {
  9.                 //alert(cBox.value);            
  10.                 url='checkuse.php?ctname='+cBox.value;
  11.                 http.open("GET", url, true);
  12.                 http.onreadystatechange = function()
  13.                         {
  14.                             if (http.readyState == 4) 
  15.                             {
  16.                                 if(http.responseText)
  17.                                 {
  18.                                     alert(http.responseText);
  19.                                     return true;
  20.                                 }
  21.                                 else
  22.                                 {
  23.                                     alert(http.responseText);
  24.                                     return false;
  25.                                 }
  26.  
  27.                             }
  28.                         }
  29.                 http.send(null);
  30.             }
  31.         }
  32.         //return false;
  33.     }
  34.     function getHTTPObject()     
  35.     {
  36.  
  37.         var xmlhttp;
  38.  
  39.         if (window.ActiveXObject)
  40.  
  41.         {
  42.             try 
  43.             {
  44.                 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  45.             }
  46.             catch (e)
  47.             {
  48.                 try
  49.                 {
  50.                     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  51.                 }
  52.                 catch (E) 
  53.                 {
  54.                     xmlhttp = false;
  55.                 }
  56.             }
  57.         }
  58.  
  59.         else
  60.         {
  61.             xmlhttp = false;
  62.         }
  63.         if (window.XMLHttpRequest) 
  64.         {
  65.             try
  66.             {
  67.                 xmlhttp = new XMLHttpRequest();
  68.             } 
  69.             catch (e) 
  70.             {
  71.                 xmlhttp = false;
  72.             }
  73.         }
  74.  
  75.         return xmlhttp;
  76.  
  77.     }
  78. //HTTP Objects..
  79.  
  80. var http = getHTTPObject();
  81.  
and here is the PHP code running in background....

[PHP]
<?php
require('connection.php');
$CompTName=$_GET['ctname'];
$query="select Flag from TCOMPONENTTYPE where ComponentTypeName='$CompTName'";
echo $query;
list($result)=mysql_fetch_row(mysql_query($query)) ;
if($result>0)
{
echo 0;
}
else
{
echo 1;
}
//echo $result;
?>

[/PHP]
Dec 13 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

i assume you call confirm_use() later on? could you try to use only one iteration so that you only would make one single ajax call? ... i think you could use something like the following to make it work:

Expand|Select|Wrap|Line Numbers
  1. // define a global req-array
  2. var req = [];
  3.  
  4. // later on in your code (orig. post it is line 7) do the
  5. // following
  6.  
  7. if(cBox.checked) {
  8.     req[req.length] = getHTTPObject();
  9.  
  10.     // now use the last created request-object in your further code
  11.     // your code follows here 
  12. }
  13.  
kind regards
Dec 13 '07 #4
rpnew
188 100+
hi ...

i assume you call confirm_use() later on? could you try to use only one iteration so that you only would make one single ajax call? ... i think you could use something like the following to make it work:

Expand|Select|Wrap|Line Numbers
  1. // define a global req-array
  2. var req = [];
  3.  
  4. // later on in your code (orig. post it is line 7) do the
  5. // following
  6.  
  7. if(cBox.checked) {
  8.     req[req.length] = getHTTPObject();
  9.  
  10.     // now use the last created request-object in your further code
  11.     // your code follows here 
  12. }
  13.  
kind regards
Hi well,
even here i'm making only one Ajax call as in loop if the checkbox is checked then only it will go in IF loop otherwise will sinply bypass it..... however i'm trying your suggestion and i'll get back to you with result...

Regards,
RP
Dec 13 '07 #5
rpnew
188 100+
Hi gits

It is still having the same problem....... however i've changed the code a bit....
and here is the changed script code......

Expand|Select|Wrap|Line Numbers
  1.  
  2. function confirm_use()
  3.     {
  4.  
  5.         var tbl=document.getElementById("ctypedelete");
  6.         for(i=0;i<tbl.tBodies[0].rows.length-1;i++)
  7.         {
  8.  
  9.             var cBox=document.getElementsByName('compt[]')[i];
  10.             if(cBox.checked)
  11.             {
  12.                 var http = getHTTPObject();
  13.                 alert(cBox.value);            
  14.                 url='checkuse.php?ctname='+cBox.value;
  15.                 http.open("GET", url, true);
  16.                 http.onreadystatechange = function()
  17.                         {
  18.                             if (http.readyState == 4) 
  19.                             {
  20.                                 alert(http.responseText);
  21.                             }
  22.                         }
  23.                 http.send(null);
  24.             }
  25.         }
  26.         return false;
  27.     }
  28.  
  29.  
  30.  
  31.  
Dec 13 '07 #6
gits
5,390 Expert Mod 4TB
hi ...

i think you should use different instances of the request object ... is ONE and only one call working?
Dec 13 '07 #7
rpnew
188 100+
hi ...

i think you should use different instances of the request object ... is ONE and only one call working?
Hi,
Nope even single call is not working...... but when i started working, i mean writing script it was working perfectly...... but now dont know whats the problem its not showing any response from the script......

Another thing is even with LOOPS it is making only one call to script.... the loop is simply for navigating through table and getting the value of the RADIO button. If it is checked then only it makes AJAX call.......

Regards,
RP
Dec 13 '07 #8
gits
5,390 Expert Mod 4TB
Another thing is even with LOOPS it is making only one call to script.... the loop is simply for navigating through table and getting the value of the RADIO button. If it is checked then only it makes AJAX call.......
not with your code ... in case you have the corresponding checkbox in a row checked then you overwrite http with a new request-object and start to send it ...

i'll have a closer look at it ...

kind regards
Dec 13 '07 #9
rpnew
188 100+
not with your code ... in case you have the corresponding checkbox in a row checked then you overwrite http with a new request-object and start to send it ...

i'll have a closer look at it ...

kind regards

Hi,
I still dont think so. If any checkbox is not checked then how that IF condition will satisfy and if it is not satisfied then how can it go into that IF condition part....

Anyways.. i'm still stuck with this problem and not getting any solutions....

Even if whatever you are saying is true.. then my question is why was it working earlier and not now??


Regards,
RP
Dec 13 '07 #10
gits
5,390 Expert Mod 4TB
I still dont think so. If any checkbox is not checked then how that IF condition will satisfy and if it is not satisfied then how can it go into that IF condition part....
sorry ... you misunderstood ... of course ... in case you don't have a checkbox checked ... NO call is made, check one, one call is made but now check more than one ... the http is overwritten in every step the check is true ... ok?

so now i thought that using one checked box to make one! call ... and as you said it won't work either? ... so i'll have a closer look at it may be i overlooked something ...

kind regards
Dec 13 '07 #11
rpnew
188 100+
sorry ... you misunderstood ... of course ... in case you don't have a checkbox checked ... NO call is made, check one, one call is made but now check more than one ... the http is overwritten in every step the check is true ... ok?

so now i thought that using one checked box to make one! call ... and as you said it won't work either? ... so i'll have a closer look at it may be i overlooked something ...

kind regards
hmm,
You are right and i think you are misguided by me only... here its not actually a "CHECKBOX" its a "RADIO" button... sorry for that... so it will select only one at a time....

well thanks for explanation and if you find any solution get back to this post.... its bugging me like anything..... as i need to use this at many places in my project...

Regards,
RP
Dec 13 '07 #12
rpnew
188 100+
Hi all,

Please have a look at this problem and help me find solution... its taking lots of time in my project..

Regards,
RP
Dec 14 '07 #13
Dasty
101 Expert 100+
I took just core ajax part from your code and tried it. It works ...

Expand|Select|Wrap|Line Numbers
  1. function confirm_use()
  2. {
  3.   var http = getHTTPObject();
  4.   url='test.txt';
  5.   http.open("GET", url, true);
  6.   http.onreadystatechange = function()
  7.   {
  8.     if (http.readyState == 4) 
  9.     {
  10.       alert(http.responseText);
  11.     }
  12.   }
  13.   http.send(null);
  14.   return false;
  15. }
  16.  
So ajax and XHR is not source of your problem. It has something to do with yor Loop or getting elements from page. Is alert(cBox.value); showing you something? For exmaple getElementsByName('compt[]') looks little weird.
Dec 14 '07 #14
rpnew
188 100+
I took just core ajax part from your code and tried it. It works ...

Expand|Select|Wrap|Line Numbers
  1. function confirm_use()
  2. {
  3.   var http = getHTTPObject();
  4.   url='test.txt';
  5.   http.open("GET", url, true);
  6.   http.onreadystatechange = function()
  7.   {
  8.     if (http.readyState == 4) 
  9.     {
  10.       alert(http.responseText);
  11.     }
  12.   }
  13.   http.send(null);
  14.   return false;
  15. }
  16.  
So ajax and XHR is not source of your problem. It has something to do with yor Loop or getting elements from page. Is alert(cBox.value); showing you something? For exmaple getElementsByName('compt[]') looks little weird.
Hi,

yeah. alert(cBox.value) gives the value of the selected RADIO button from the table(which i'm sending to script).. so i think getElementsByName('compt[]').. is working....so may be something wrong with the loop as you are suggesting... but dont know whats the problem....

Regards,
RP
Dec 14 '07 #15
omerbutt
638 512MB
I took just core ajax part from your code and tried it. It works ...

Expand|Select|Wrap|Line Numbers
  1. function confirm_use()
  2. {
  3.   var http = getHTTPObject();
  4.   url='test.txt';
  5.   http.open("GET", url, true);
  6.   http.onreadystatechange = function()
  7.   {
  8.     if (http.readyState == 4) 
  9.     {
  10.       alert(http.responseText);
  11.     }
  12.   }
  13.   http.send(null);
  14.   return false;
  15. }
  16.  
So ajax and XHR is not source of your problem. It has something to do with yor Loop or getting elements from page. Is alert(cBox.value); showing you something? For exmaple getElementsByName('compt[]') looks little weird.

hi
going through your convo first i work with asp rather than php but the prob was the script part so just took part in it .......importantly place this one check also in you
change_value() function
Expand|Select|Wrap|Line Numbers
  1. if(http.readystate==4)
  2. {
  3.     //try puttingan alert here and check wether it comes into this if
  4.     if(http.status==200)//this assures eveery thing has been done fine 
  5.      {
  6.         //here go withyour responsetext code
  7.      }
  8. }
  9.  
secondly why dont you use a form object to acess the elements of the form
i have used the following way for access and save to a string by concatination to pass it with the xml.send() by using the post method ,i would show its more likely same like chaving checks but using a lil diff method here look at it
Expand|Select|Wrap|Line Numbers
  1. function Getformvalues(fobj,valFunc)//fobj:form object,valFunc:string
  2. {
  3. //note:you can create you form object element here if you 
  4. //dont want to pass in a function in this way 
  5. //var fobj=document.forms["form name"]
  6. //use fobj.elements[i] method where i represents the name of the element i.e
  7. //in your case check box
  8.     var str;
  9.     str="";
  10.     var cmd;
  11.     cmd="";
  12.     var val;
  13.     val="";
  14.  
  15. for(var i=0;i<fobj.elements.length;i++)//start loop till length of form elements
  16.     {
  17.     switch(fobj.elements[i].type)//switch by type             {
  18.         case "text"://case for the text type
  19.         if(valFunc)
  20.         {
  21.         cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
  22.         val = eval('cmd');//validate if it is sting 
  23.         }
  24.     str += fobj.elements[i].name + "=" + fobj.elements[i].value + "&";//string concatination it will look like "elementname="elementvalue
  25.         break;
  26.  
  27.         case "select-one"://for selection menus 
  28. str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
  29.         break;
  30.         }
  31.     }
  32.     str = str.substr(0,(str.length - 1));
  33.     return str;
  34. }
  35.  
what looks to me if you change your code like the following 1 and then try
change the form names and elements names according to your desired ones
but i still want to be confirmed about these things
ctypedelete
compt[]
Expand|Select|Wrap|Line Numbers
  1. function confirm_use()
  2.     {
  3.         var fobj;//declare a variable to save the form object 
  4.          fobj=document.forms["form name"];//save in the variable
  5.         var tbl=document.getElementById("ctypedelete");
  6.         for(i=0;i<fobj.elements.length-1;i++)
  7.         {
  8.              var cBox=document.getElementsByName('compt[]')[i];
  9.             if(cBox.checked)
  10.             {
  11.                 var http = getHTTPObject();
  12.                 alert(cBox.value);      
  13.                 url="checkuse.php"
  14.                 url=url+"?ctname="
  15.                 url=url+cBox.value;
  16.                alert(url);//check ur usrl string also if it is correct
  17.                 http.onreadystatechange = function()
  18.                         {
  19.                             if (http.readyState == 4) 
  20.                             {
  21.                                   alert("INTO READY STATE");
  22.                                  if(http.status==200)
  23.                                  {
  24.                                     alert(http.responseText);
  25.                                  }
  26.                                  else
  27.                                   {
  28.                                        alert("not in ready state");
  29.                                   }
  30.                             }
  31.                         }     
  32.                 http.open("GET", url, true);
  33.                            http.send(null);
  34.             }
  35.         }
  36.         return false;
  37.     }
  38.  
  39.  
Dec 14 '07 #16
rpnew
188 100+
Hi,
I've tried your first suggestion and here is my code.... It prompts the first Alert box that says "Ready Donut" but neither from following two... that is neither from the IF condition nor from the ELSE condition.... so what could be the problem now.......

Expand|Select|Wrap|Line Numbers
  1. function confirm_use()
  2.     {
  3.  
  4.         var tbl=document.getElementById("ctypedelete");
  5.         for(i=0;i<tbl.tBodies[0].rows.length-1;i++)
  6.         {
  7.  
  8.             var cBox=document.getElementsByName('compt[]')[i];
  9.             if(cBox.checked)
  10.             {
  11.                 var http = getHTTPObject();
  12.                 alert(cBox.value);            
  13.                 url='checkuse.php?ctname='+cBox.value;
  14.                 alert(url);
  15.                 http.open("GET", url, true);
  16.                 http.onreadystatechange = function()
  17.                         {
  18.                             if (http.readyState==4) 
  19.                             {
  20.                                 alert('Ready donut');
  21.                                 if(http.status==200)
  22.                                 {
  23.                                     alert('hi');
  24.                                     alert(http.responseText);
  25.                                 }
  26.                                 else
  27.                                 {
  28.                                     alert('No donut');
  29.                                 }
  30.                             }
  31.                         }
  32.                 http.send(null);
  33.             }
  34.         }
  35.         return false;
  36.     }
  37.  

Regards,
RP
Dec 14 '07 #17
Dasty
101 Expert 100+
Oh, cycle ... sure. Well, if your alert(cBox.value) shows values, problem is somewhere else.
Let's look at it:
- You are creating http variable locally in function.
- And you are creating handler for onreadystatechange event as local function as well.

So, that event handler function creates closure (because it is referenced outside in instance of XHR object). But (because of cycle) all http request objects share same cloure (we did not leave function), so when you are referencing http variable inside of onreadystatechange handler, you are referencing the SAME object for all http requests. Which is bad.

Create new function for sending request out of loop, that every instance of XHR got it's own http variable in its closure.

Try this:

Expand|Select|Wrap|Line Numbers
  1. function confirm_send(url)
  2. {
  3.   var http = getHTTPObject();
  4.   http.open("GET", url, true);
  5.   http.onreadystatechange = function()
  6.   {
  7.     if (http.readyState == 4) 
  8.     {
  9.       alert(http.responseText);
  10.     }
  11.   }
  12.   http.send(null);
  13. }
  14.  
  15. function confirm_use()
  16. {
  17.   var tbl=document.getElementById("ctypedelete");
  18.   for(i=0;i<tbl.tBodies[0].rows.length-1;i++)
  19.   {
  20.     var cBox=document.getElementsByName('compt[]')[i];
  21.     if(cBox.checked)
  22.     {
  23.       alert(cBox.value);            
  24.       url='checkuse.php?ctname='+cBox.value;
  25.       confirm_send(url);
  26.     }
  27.   return false;
  28. }   
  29.  
if it wont help, send us more of your code, that we can eventually try it by ourselves.
Dec 14 '07 #18
rpnew
188 100+
Oh, cycle ... sure. Well, if your alert(cBox.value) shows values, problem is somewhere else.
Let's look at it:
- You are creating http variable locally in function.
- And you are creating handler for onreadystatechange event as local function as well.

So, that event handler function creates closure (because it is referenced outside in instance of XHR object). But (because of cycle) all http request objects share same cloure (we did not leave function), so when you are referencing http variable inside of onreadystatechange handler, you are referencing the SAME object for all http requests. Which is bad.

Create new function for sending request out of loop, that every instance of XHR got it's own http variable in its closure.

Try this:

Expand|Select|Wrap|Line Numbers
  1. function confirm_send(url)
  2. {
  3.   var http = getHTTPObject();
  4.   http.open("GET", url, true);
  5.   http.onreadystatechange = function()
  6.   {
  7.     if (http.readyState == 4) 
  8.     {
  9.       alert(http.responseText);
  10.     }
  11.   }
  12.   http.send(null);
  13. }
  14.  
  15. function confirm_use()
  16. {
  17.   var tbl=document.getElementById("ctypedelete");
  18.   for(i=0;i<tbl.tBodies[0].rows.length-1;i++)
  19.   {
  20.     var cBox=document.getElementsByName('compt[]')[i];
  21.     if(cBox.checked)
  22.     {
  23.       alert(cBox.value);            
  24.       url='checkuse.php?ctname='+cBox.value;
  25.       confirm_send(url);
  26.     }
  27.   return false;
  28. }   
  29.  
if it wont help, send us more of your code, that we can eventually try it by ourselves.

Hi,
i checked this one as well but result is same.... let me put my code here...

Expand|Select|Wrap|Line Numbers
  1. function confirm_send(ustr)
  2.     {
  3.         var http = getHTTPObject();
  4.         http.open("GET", url, true);
  5.         http.onreadystatechange = function()
  6.                 {
  7.                     if (http.readyState==4) 
  8.                     {
  9.                         alert('Ready donut');
  10.                         alert(http.responseText);
  11.                     }
  12.                 }
  13.                 http.send(null); 
  14.     }
  15.     function confirm_use()
  16.     {
  17.  
  18.         var tbl=document.getElementById("ctypedelete");
  19.         for(i=0;i<tbl.tBodies[0].rows.length-1;i++)
  20.         {
  21.  
  22.             var cBox=document.getElementsByName('compt[]')[i];
  23.             if(cBox.checked)
  24.             {
  25.                 alert(cBox.value);            
  26.                 url='checkuse.php?ctname='+cBox.value;
  27.                 alert(url);
  28.                 confirm_send(url);
  29.  
  30.             }
  31.  
  32.         }
  33.  
  34.         return false;
  35.     }
  36.  
Here is the code according to your suggestion, if i'm missing something let me know.... anyways... it still shows empty Alert Box in place of alert(http.responseText); while all other Alert boxes are working perfectly...
One more thing i would like to mention here is...... when i put this url which i'm using in the code directly into address bar the PHP script shows the proper reply on page while with code it dosent work........

Another thing i like to mention once again is i'm using FireBug for FireFox which shows that URL i'm passing is perfect, but it dosent show anything in the HEADER tab and just 'Loading....' in the response text and shows that HttpResponse has failed...........


Regards,
RP
Dec 17 '07 #19
gits
5,390 Expert Mod 4TB
is your php-script working properly and does the query give you any result?
Dec 17 '07 #20
rpnew
188 100+
is your php-script working properly and does the query give you any result?
Hi,

yeah as i mentioned in my last post... when i put the URL ,used in the code, in the address bar it gives the proper output but when i use it with the HttpResponse it gives me blank reply.........
Dec 17 '07 #21
gits
5,390 Expert Mod 4TB
could you try a post request?

Expand|Select|Wrap|Line Numbers
  1. function confirm_send_post(params) {
  2.     var http = getHTTPObject();
  3.  
  4.     http.open('POST', 'checkuse.php', true);
  5.  
  6.     http.setRequestHeader(
  7.         'Content-Type',
  8.         'application/x-www-form-urlencoded'
  9.     );
  10.  
  11.     http.onreadystatechange = function() {
  12.         if (http.readyState==4) {
  13.             alert('Ready donut');
  14.             alert(http.responseText);
  15.         }
  16.     }
  17.  
  18.     http.send(params);
  19. }
  20.  
  21. function confirm_use() {
  22.     var tbl=document.getElementById('ctypedelete');
  23.  
  24.     for(i = 0; i < tbl.tBodies[0].rows.length-1; i++) {
  25.         var cBox=document.getElementsByName('compt[]')[i];
  26.  
  27.         if(cBox.checked) {
  28.             var params = 'ctname=' + cBox.value;
  29.             confirm_send_post(params);
  30.         }
  31.     }
  32.  
  33.     return false;
  34. }
  35.  
Dec 17 '07 #22
rpnew
188 100+
could you try a post request?

Expand|Select|Wrap|Line Numbers
  1. function confirm_send_post(params) {
  2.     var http = getHTTPObject();
  3.  
  4.     http.open('POST', 'checkuse.php', true);
  5.  
  6.     http.setRequestHeader(
  7.         'Content-Type',
  8.         'application/x-www-form-urlencoded'
  9.     );
  10.  
  11.     http.onreadystatechange = function() {
  12.         if (http.readyState==4) {
  13.             alert('Ready donut');
  14.             alert(http.responseText);
  15.         }
  16.     }
  17.  
  18.     http.send(params);
  19. }
  20.  
  21. function confirm_use() {
  22.     var tbl=document.getElementById('ctypedelete');
  23.  
  24.     for(i = 0; i < tbl.tBodies[0].rows.length-1; i++) {
  25.         var cBox=document.getElementsByName('compt[]')[i];
  26.  
  27.         if(cBox.checked) {
  28.             var params = 'ctname=' + cBox.value;
  29.             confirm_send_post(params);
  30.         }
  31.     }
  32.  
  33.     return false;
  34. }
  35.  
Hi,
Even POST is not working still it is showing the alert(http.responsetext) as blank...

I'm really stuck here........

Regards,
RP
Dec 17 '07 #23
gits
5,390 Expert Mod 4TB
could you try to trace whether your php-script is really called and excuted or not by the request?
Dec 17 '07 #24
rpnew
188 100+
could you try to trace whether your php-script is really called and excuted or not by the request?
Hi,
this is what happening exactly.....

I'm using FireFox and using FireBug to debug......
As you can see in my code i've put Alert boxes at many places to check the state of the code....
Now what is happening........

When i'm calling the function involving the XHR it shows the blank response......

And in FireBug..

it shows the right parameters i'm passing(i suppose that means it is calling the right URL)...... (in the parameters tab)
It is blank (in Headers tab)
It shows Loading...... (in Response tab)....

And it shows that response has failed.......

On the other side when i put the URL used or generated in this code directly into Address Bar it shows the proper reply(So i suppose script is working fine)

One more strange thing i'd found is........ when i'm putting a breakpoint into script and executing it step by step it is showing the proper response... but without breakpoint it shows the blank one as usual..........

Regards,
RP
Dec 18 '07 #25
gits
5,390 Expert Mod 4TB
very strange indeed ... do you have a link to a testpage, so that we might have a closer look at the problem?

lets assume the problem:

the request is working well ... the php-script too and it executes and gives the resultset ... now the responseText is empty ...

one really strange thing is that in an earlier post we could see that the request-objects status didn't work ... so now i think i'd need to see the entire page ... perhaps pm it to me and i'll have a close look at it ... or as i said ... a link to a testpage would be fine ...

kind regards
Dec 18 '07 #26
Dasty
101 Expert 100+
Post it here or PM code to me as well. Really want see the reason too.
(seems like it has problems when you are sending many requests as "burst")

I got strange feeling in my stomach that I missed something simple again :)
Dec 18 '07 #27
rpnew
188 100+
Hi,
As i'm working on local machine i cant send you the testpage but here is the code.......

Following is the php page on which i'm using Ajax
[PHP]
<?php

//print_r($_REQUEST);
require("connection.php");
foreach($_POST['compt'] as $compt)
{
$dele="delete from TCOMPONENTTYPE where ComponentTypeName='$compt'";
//mysql_query($dele);
print("<br>");
}

$sql="select ComponentTypeName from TCOMPONENTTYPE";
//echo $sql;
$result = mysql_query($sql);
?>

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#82B6D7">
<br><br>
<center>
<?php print("<form name=\"comptform\" action=\"adminframes801.php\" method=\"POST\" onSubmit=\"javascript: return confirm_delete();\">"); ?>
<table border="1" align="center" id="ctypedelete">
<caption>Delete Component Type(s)</caption>
<?php
while(list($ComptName)=mysql_fetch_array($result))
{
print("<tr><td><input type=\"radio\" name=\"compt[]\" value='$ComptName'>$ComptName</td></tr>");
}

?>
<tr><td><input type="submit" value="delete" ><input type="button" value="cancel" onClick="javascript: window.open('blankdefault.php','frm_form');"></td></tr>
</table>
</form>
</center>
<script>
<!--

function confirm_delete()
{
var agre=confirm('are you sure you want to delete the data???') ;
if(!agre) return false;
else if(!confirm_use())
{
return true;
}
else
{
return true;
}
}
function confirm_send(ustr)
{
var http = getHTTPObject();
http.open('GET', ustr, true);
alert(ustr);
http.onreadystatechange = function()
{
if (http.readyState==4)
{
alert('Ready donut');
alert(http.responseText);
}
}
http.send(null);
}
function confirm_use()
{

var tbl=document.getElementById("ctypedelete");
for(i=0;i<tbl.tBodies[0].rows.length-1;i++)
{

var cBox=document.getElementsByName('compt[]')[i];
if(cBox.checked)
{
alert(cBox.value);
url='checkuse.php?ctname='+cBox.value;
alert(url);
confirm_send(url);

}

}

return false;
}
function getHTTPObject()
{

var xmlhttp;

if (window.ActiveXObject)

{
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
xmlhttp = false;
}
}
}

else
{
xmlhttp = false;
}
if (window.XMLHttpRequest)
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch (e)
{
xmlhttp = false;
}
}

return xmlhttp;

}
-->
</script>
</body>
</html>
[/PHP]

And following is the background PHP script.
[PHP]
<?php
require('connection.php');
$CompTName=$_GET['ctname'];
$query="select Flag from TCOMPONENTTYPE where ComponentTypeName='$CompTName'";
//echo $query;
list($result)=mysql_fetch_row(mysql_query($query)) ;
if($result>0)
{
echo 0;
}
else
{
echo 1;
}
//echo $result;
?>
[/PHP]


Now what i'm doing is...... On first page user will get the option for deleting some values.... If they are used somewhere in database then the user wont be allowed to delete it. and i need to prompt a message regarding the same.......

Regards,
RP
Dec 18 '07 #28
Dasty
101 Expert 100+
Well, you are calling asynchronous ajax request, but your code is writen like request is synchronous. So your code works like that:

1) starting ajax request
2) sending form
3) getting ajax response

So, you are getting / handling response after page is submitted (is gone), so result is weird.

Try to change this function:

Expand|Select|Wrap|Line Numbers
  1. function confirm_delete()
  2. {
  3.   var agre=confirm('are you sure you want to delete the data???') ;
  4.   if(!agre) return false;
  5.   else if(!confirm_use())
  6.   {
  7.     return false;
  8.   }
  9.   else
  10.   {
  11.     return false;
  12.   }
  13. }
This way, forum wont be submitted and you get valid ajax response. (this is not solving your problem ... i just wanted you to see why it does not work)

You have 2 options:

1) use synchronous ajax (http.open('GET', ustr, false);) so you can work with result right after send command in your code
2) rewrite the code, so the form is submitted AFTER onreadychange handler is processed

If you need further assistence with that, tell me ...
Dec 18 '07 #29
gits
5,390 Expert Mod 4TB
yep ... i agree ... the problem is the return true in confirm_delete ...
Dec 18 '07 #30
Dasty
101 Expert 100+
replace lines 42-70 with this code:

Expand|Select|Wrap|Line Numbers
  1.  
  2.   var response_received = false;
  3.  
  4.   function confirm_delete()
  5.   {
  6.     if (response_received) return true;
  7.     var agre=confirm('are you sure you want to delete the data???') ;
  8.     if(!agre) return false;
  9.     confirm_use();
  10.     return false;
  11.   }
  12.   function confirm_send(ustr)
  13.   {
  14.     var http = getHTTPObject();
  15.     http.open('GET', ustr, true);
  16.     alert(ustr);
  17.     http.onreadystatechange = function()
  18.     {
  19.       if (http.readyState==4) 
  20.       {
  21.         alert('Ready donut');
  22.         alert(http.responseText);
  23.         // validate response here and check if you want to send the form
  24.         if (true) // if so
  25.         {
  26.           response_received = true;
  27.           comptform.submit();
  28.         }
  29.       }
  30.     }
  31.     http.send(null); 
  32.   }
This is solution for Option 2 described in my post above (because I dont like synch ajax calls :)
Dec 18 '07 #31
rpnew
188 100+
hey friends....

Thank you very much.... It seems working again.......
If something goes wrong i'll get back to you ......

Regards,
RP
Dec 19 '07 #32

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

Similar topics

1
by: Ryann | last post by:
I hate javascript looking for help. I am trying to pass hidden fields around without showing a query string in the address bar. e.g. formA.asp not formA.asp?var1=blah&var2=blah I have...
3
by: spmm# | last post by:
Hi! My ASP.NET page gets a pdf-file from a SQLServer database and writes it in a browserwindow, using Response.BinaryWrite. It basically looks like this: public class WebForm1 :...
0
by: abraham | last post by:
Hi In an .aspx codebehind file I retrieve a file from a database and write it to the response buffer, so the browser pops up a 'save file' dialog and the user can save the file to disk. The...
4
by: Green | last post by:
Hi, I have an urgent question about showing the PDF. I got the following message: Some files can harm your computer. If the file information below looks suscipcious, or you do not fully trust...
7
by: Shapiro | last post by:
I have a scenario where I log a resquest to a database table and update the request with a corresponding response including the response time. I am using an HttpModule to do this. My challenge...
1
by: Eric | last post by:
I have the following situation: I was getting intermittent errors using Reponse.Redirct("url", true) and was trying to catch the ThreadAbortException, but it was not staying caught and was showing...
2
by: Incorrect filenames in download link. | last post by:
Hi experts, I am giving filename as "clearbenefits.infosys.txt" to Response.AddHeader as filename parameter. After clicking the download link filename on dialogbox is showing as...
5
by: John Kotuby | last post by:
Hi all, This is my first time trying to creaet and use a custome Web Control in a Web Site project in ASP.NET 2.0 with VS 2005 and VB. I created the control in a separate Web Control Library...
1
by: ollielaroo | last post by:
Hi guys, Firstly I did do a search for this one first but I couldn't find anything related in this forum. I am using Dreamweaver MX and trying to build admin pages for an ASP site. My problem is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.