Problem with Subsequent Calls In a Ajax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harikumarmpl
    New Member
    • Sep 2008
    • 4

    #1

    Problem with Subsequent Calls In a Ajax

    Hi to all

    Here i have a problem,

    I have a search form in that one which is for searching the usernames in the database
    It works fine when i search the UserNames at first time.

    When i have changed the UserName in the text box and submits then it is not making a request and fetch the details from the server.
    After first request if i have checked with alerts the http_request.re adyStatus=1

    For this i am pulling out my hair and googling it and many things i am doing it
    can any body help on this please

    here i am providing the code for the ajax
    Code:
     function makePOSTRequest(url, divTag, params) {
          var http_request = false;
         
          if (window.XMLHttpRequest) { // Mozilla, Safari,...
             http_request = new XMLHttpRequest();
             if (http_request.overrideMimeType) {
             	// set type accordingly to anticipated content type
                //http_request.overrideMimeType('text/xml');
                http_request.overrideMimeType('text/html');
             }
          } else if (window.ActiveXObject) { // IE
             try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
             } catch (e) {
                try {
                   http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
             }
          }
           if (!http_request) {
             alert('Cannot create XMLHTTP instance');
             return null;
             
          }
          http_request.open('POST', url, true);
          http_request.onreadystatechange = function(){ var x = alertContents(divTag,http_request)};
          
          http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
          http_request.setRequestHeader("Content-length", params.length);
          http_request.setRequestHeader("Connection", "close");
          http_request.setRequestHeader("Cache-Control","no-cache");
          http_request.send(params);
       }
    
       function alertContents(divTag,http_request) {
          alert(http_request.readyState);
          if (http_request.readyState == 4) {
              alert(http_request.status);
             if (http_request.status == 200) {
                //alert(http_request.responseText);
                result = http_request.responseText;
                document.getElementById(divTag).innerHTML = result; 
                http_request = false;
             } else {
                alert('There was a problem with the request.');
                http_request = false;
             }
          }
       }
    
    
       function retrieveSearchResults(url,divTag,params){
          alert(url+"\n"+divTag+"\n"+params);
          makePOSTRequest(url,divTag,params);
       }
    and here is the code where i am making the call to ajax
    Code:
    <form action="javascript:retrieveSearchResults('searchResults.jsp','myspan','UserName='+escape(document.getElementById('UserName').value));" name="myform" id="myform" >
     <table cellspacing="2" cellpadding="1" border="0" width="40%" align="center">
    <tr>
        <td>User Name</td>
        <td><input type="text" name="UserName" size="15"></td>
        <td></td>
    </tr>
    
    <tr>
        <td>User Course</td>
        <td><input type="text" name="UserCourse" size="15"></td>
        <td></td>
        <td><input type="Reset" value="clear" style="width:50px;"></td>
        <td><input type="submit" name="go" value="go" style="width:50px;"></td>
    </tr>
    
    
    </table>
    </form>
    In this one i will search for the UserName

    Thanks In Advance
    Hari
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Maybe the result is being cached. Have you tested in all browsers?

    Comment

    Working...