SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Could not get the value for Auto Suggestion

    I'm trying to work the Auto suggestion in Ajax.
    It works well in my local computer, but doesn't work online.
    I think XMLHttpRequest doesn't seem work properly, but not sure about that.
    Please help me if any expert coders has any advices.

    remotesuggestion.js

    /**
    * Provides suggestions for state names (USA).
    * @class
    * @scope public
    */
    function RemoteStateSuggestions() {

    /*
    if (typeof XMLHttpRequest != "undefined") {
    this.http = new XMLHttpRequest();
    } else if (typeof ActiveXObject != "undefined") {
    //this.http = new ActiveXObject("MSXML2.XmlHttp");
    this.http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
    alert("No XMLHttpRequest object available. This functionality will not work.");
    }
    */
    if (window.XMLHttpRequest) {
    this.http = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    this.http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
    this.http = null;
    }
    }

    /**
    * Request suggestions for the given autosuggest control.
    * @scope protected
    * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
    */
    RemoteStateSuggestions.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
    bTypeAhead /*:boolean*/) {

    var oHttp = this.http;

    //if there is already a live request, cancel it
    if (oHttp.readyState != 0) {
    oHttp.abort();
    }
    // var abc = encodeURIComponent(oAutoSuggestControl.textbox.value);
    //alert(oAutoSuggestControl.textbox.value);
    //build the URL
    var sURL = "suggestionsMyPaper.php?userInput=" + encodeURIComponent(oAutoSuggestControl.textbox.value);

    //open connection to states.txt file
    oHttp.open("get", sURL , true);

    oHttp.onreadystatechange = function () {
    if (oHttp.readyState == 4) {
    //evaluate the returned text JavaScript (an array)
    var aSuggestions = eval(oHttp.responseText);
    alert(aSuggestions);
    //provide suggestions to the control
    oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
    }
    }

    //oHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    oHttp.send("");
    }
    suggestions.php
    <?php
    header("Content-Type: text/plain; charset=UTF-8");

    include("services/AutosuggestionService.php");

    session_start();
    $global_uni = $_SESSION['global_uni'];
    $global_id = $_SESSION['global_id'];

    $service = new AutosuggestionService;
    $result = $service->CheckPapers($global_uni);

    while ($ob = mysql_fetch_object($result)) {
    $states[] = $ob->paper_code;
    }


    $suggestions = array();

    if (strlen($userInput) > 0){

    $userInputLC = strtolower($userInput);

    for ($i=0; $i < count($states); $i++) {

    $stateLC = strtolower($states[$i]);

    $result = strpos($stateLC, $userInputLC);
    if ($result !== false && $result == 0) {
    array_push($suggestions, $userInput.substr($states[$i], strlen($userInput)));
    }
    }
    }
    ?>
    [<?php
    for ($i = 0; $i < count($suggestions); $i++) {
    if ($i > 0) {
    echo ",";
    }
    echo "\"".$suggestions[$i]."\"";

    }
    ?>]
    Any solution will be very appreciated!!
    Thanks

  2. #2
    SitePoint Addict ALL's Avatar
    Join Date
    Oct 2005
    Location
    South Dakota
    Posts
    215
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    what is it doing? how is it not working? where can we see a demo? these would all be usefull to answer.

    -ALL
    Did I help you?
    You can repay me, support one of my projects (no money needed):
    JavaScript Wiki, Another Web Forum, Paranormal Site


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •