ajax readyState 1 wall

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gp

    #1

    ajax readyState 1 wall

    This code is stopping ...I can't get past readyState == 1....
    for testing purposes my searchDB.php is simply:
    <?php
    echo "string blahahahahah blahahaha hahahahhb ahaha";
    ?>

    newK is <input idit is dynamically created with php at the time the
    form loads...there up to 28 <input>
    that will have the google type search suggestion <div>. srchK is the
    <div idgenerated for each corresponding <input>

    var xhr;

    function XHR() {
    if (window.XMLHttp Request) {
    xhr = new XMLHttpRequest( );
    } else if (window.ActiveX Object) {
    xhr = new ActiveXObject(
    "Microsoft.XMLH TTP");
    }
    return xhr;
    }

    function searchDB(newK, srchK) {
    var http = XHR();

    var str = escape($(newK). value);
    http.open('POST ', 'http://my.url.here/searchDB.php', true);
    http.setRequest Header("Content-type",
    "applicatio n/x-www-form-urlencoded; charset=UTF-8");
    http.onreadysta techange = handleSearchSug gest(http, newK,
    srchK);
    http.send(str);
    }

    function handleSearchSug gest(http, newK, srchK) {
    var xhttp = http;

    if (xhttp.readySta te == 4) {
    var ss = $(srchK);
    ss.innerHTML = '';
    var str = xhttp.responseT ext;//.split("\n");
    var estr = eval(str);
    alert (estr);
    for (var i=0; i < estr.length - 1; i++ ) {
    alert (i);
    var suggest = '<div
    onmouseover="ja vascript:sugges tOver(this):" ';
    suggest += 'onmouseout="ja vascript:sugges tOut(this);"
    ';
    suggest +=
    'onclick="javas cript:setSearch (this.innerHTML , '+newK+', '+srchK+');"
    ';
    suggest += 'class="suggest _link">' + str[i] + '</div>';
    ss.innerHTML += suggest;
    }
    }

  • agapeton@gmail.com

    #2
    Re: ajax readyState 1 wall

    What's your question?












    gp wrote:
    This code is stopping ...I can't get past readyState == 1....
    for testing purposes my searchDB.php is simply:
    <?php
    echo "string blahahahahah blahahaha hahahahhb ahaha";
    ?>
    >
    newK is <input idit is dynamically created with php at the time the
    form loads...there up to 28 <input>
    that will have the google type search suggestion <div>. srchK is the
    <div idgenerated for each corresponding <input>
    >
    var xhr;
    >
    function XHR() {
    if (window.XMLHttp Request) {
    xhr = new XMLHttpRequest( );
    } else if (window.ActiveX Object) {
    xhr = new ActiveXObject(
    "Microsoft.XMLH TTP");
    }
    return xhr;
    }
    >
    function searchDB(newK, srchK) {
    var http = XHR();
    >
    var str = escape($(newK). value);
    http.open('POST ', 'http://my.url.here/searchDB.php', true);
    http.setRequest Header("Content-type",
    "applicatio n/x-www-form-urlencoded; charset=UTF-8");
    http.onreadysta techange = handleSearchSug gest(http, newK,
    srchK);
    http.send(str);
    }
    >
    function handleSearchSug gest(http, newK, srchK) {
    var xhttp = http;
    >
    if (xhttp.readySta te == 4) {
    var ss = $(srchK);
    ss.innerHTML = '';
    var str = xhttp.responseT ext;//.split("\n");
    var estr = eval(str);
    alert (estr);
    for (var i=0; i < estr.length - 1; i++ ) {
    alert (i);
    var suggest = '<div
    onmouseover="ja vascript:sugges tOver(this):" ';
    suggest += 'onmouseout="ja vascript:sugges tOut(this);"
    ';
    suggest +=
    'onclick="javas cript:setSearch (this.innerHTML , '+newK+', '+srchK+');"
    ';
    suggest += 'class="suggest _link">' + str[i] + '</div>';
    ss.innerHTML += suggest;
    }
    }

    Comment

    • Michael Winter

      #3
      Re: ajax readyState 1 wall

      gp wrote:

      [snip]
      var xhr;
      A global variable to which you assign, and yet return from a function? Odd.
      function XHR() {
      if (window.XMLHttp Request) {
      xhr = new XMLHttpRequest( );
      } else if (window.ActiveX Object) {
      xhr = new ActiveXObject(
      "Microsoft.XMLH TTP");
      You aren't worried about MSIE throwing an exception if ActiveX is
      disabled? Consider an alternate implementation - there are examples in
      the group archives[1].

      [snip]
      var str = escape($(newK). value);
      You aren't using Prototype, are you?

      [snip]
      http.onreadysta techange = handleSearchSug gest(http, newK,
      srchK);
      Here, you are calling the handleSearchSug gest function, and assigning
      its return value to the onreadystatecha nge property. You either need to
      assign a reference directly:

      http.onreadysta techange = handleSearchSug gest;

      and modify the function appropriately, or create another function which
      takes its place and called handleSearchSug gest with the appropriate
      arguments.

      [snip]
      var suggest = '<div
      onmouseover="ja vascript:sugges tOver(this):" ';
      Here, "javascript :" is just a label and is superfluous. In MSIE, it can
      be used to switch languages, but unless VBScript has been used (and that
      would be odd, on the Web), it's still unnecessary.

      [snip]

      Mike


      [1]
      <http://groups.google.c o.uk/group/comp.lang.javas cript/msg/fa966be4e9ba398 6?hl=en>

      Comment

      Working...