views:

28

answers:

1

the responseText is empty in Firefox ,but ok in InternetExplorer i also log the response before returning to the client so i see my response there

this is my request , i added a setTimeout but this also not helping can someone help me please ,

thank you

var ajaxUrl = "./ajaxHandlers/ajax-handler.php";

var myAjax = new Ajax.Request(
  ajaxUrl,
  {
    method: 'post', 
    parameters: params, 
    onComplete: function(response)
    { 
      setTimeout(handleResponse(response,callback) ,5000);
    } 
 });



 function handleResponse(response,callback)
 {
  alert(response.responseText);

  try
  {
     eval("var r = " + response.responseText);
  }
  catch (e)
  {
     alert("EXCEPTION = " + e.constructor);

     showError("error evaluating response : Response text:<br/>" + response.responseText);
     var r = new Object();
     r.message = 'Error evaluating response';
     r.status = 'error';
     if (typeof callback == 'function') callback(r);
     return;
  }
}
+1  A: 

In the onComplete your callback variable is not defined so this causes your problem :

onComplete: function(response)
{
      handleResponse(response);
} 

or

onComplete: function(response, callback)
{
      handleResponse(response, callback);
} 

Edit: Here is the full code I have. It is working absolutely ok on FF 3.5.10 .. hmm not the latest but should be the same. I can confirm the ajax is synchronous because of the order of the console.info output statements :

var ajaxUrl = "./ajaxHandlers/ajax-handler.php";
console.info('1');

var myAjax = new Ajax.Request(
  ajaxUrl,
  {
    method: 'post',
    asynchronous: false, 
    parameters: {}, 
    onComplete: function(response, callback)
    {
      handleResponse(response,callback);
    } 
   }
 );

console.info('2');

 function handleResponse(response, callback)
 {
 console.info(response.responseText);

  try
  {
     eval("var r = " + response.responseText);
  }
  catch (e)
  {
     alert("EXCEPTION = " + e.constructor);

     showError("error evaluating response : Response text:<br/>" + response.responseText);
     var r = new Object();
     r.message = 'Error evaluating response';
     r.status = 'error';
     if (typeof callback == 'function') callback(r);
     return;
  }
}
budinov.com
thanks but still on synchronized messages i get the same
shay
also not my page is reloading after the asynchronous ajax request is done
shay
i cannot understand what you are trying to do ... supply us with more code or explain better
budinov.com
i want to send an ajax request and get the responseTexti can only do it with setting asynchronous to true i need asynchronous : false ,
shay
I updated my answer so please try it as it is ...
budinov.com
ok i got it working now m i added as u advice beforei dont know why it took me a whole day to make this workingmay be some firefox bug that require some refresh or clear the complete cache .i really dont know MY only new problem is why after the ajax request the page reload it self
shay
ok i had a form tag , thank you all
shay