Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts

    error: '1' is null or not an object in autocomplete

    Hi,

    I am new in jquery and I have code for autocomplete, but now I encountered error : '1' is null or not an object when I type letter that was not available in the database. I want to disappear that error. But I don't have any idea how can I disappear that error when I type letter which is not available or did not match in the database. But if I type letter that match in the database no error display.

    here is my code:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    
    <head>
    
    <script type="text/javascript" src="jquery.js"></script>
    <script type='text/javascript' src='jquery.autocomplete.js'></script>
    <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
    <script type="text/javascript">
    //----auto complete process name---//
    $().ready(function() {
        $("#process_name").autocomplete("get_process_list.php", {
           width: 205,
            matchContains: true,
            mustMatch: true,
            selectFirst: false
        });
        
        $("#process_name").result(function(event, data, formatted) {
            $("#process_id").val(data[1]);
        });
        
    });
    </script>
    </head>
    <body>
    <form>
    <table>
    <tr>
    <td>Process:</td>
    <td><input type="text" name="process_name" id="process_name" value="" size="30"></td>
    </tr>
    </table>
    <input type="hidden" name="process_id" id="process_id" value="" />
    </form>
    </body>
    </html>
    Any help is highly appreciated.

    Thank you

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,215
    Thanks
    12
    Thanked 338 Times in 334 Posts
    Quote Originally Posted by newphpcoder View Post
    I want to disappear that error. But I don't have any idea how can I disappear that error when I type letter which is not available or did not match in the database.
    the solution is quite simple, return an error from the server (404) so that your AJAX handler does not trigger or check the return value from the server for validaty.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    the solution is quite simple, return an error from the server (404) so that your AJAX handler does not trigger or check the return value from the server for validaty.
    What do you mean by that?? How can I return the error from server (404)?

    here is my ajax:

    Code:
    function AJAX(){
            var xmlHttp;
            try{
                xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
                return xmlHttp;
                }
            catch (e){
                try{
                    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
                    return xmlHttp;
                    }
                catch (e){
                    try{
                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                        return xmlHttp;
                        }
                    catch (e){
                        alert("Your browser does not support AJAX!");
                        return false;
                        }
                    }
                }
            }
    Thank you

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,215
    Thanks
    12
    Thanked 338 Times in 334 Posts
    Quote Originally Posted by newphpcoder View Post
    What do you mean by that?? How can I return the error from server (404)?
    as a very simple example:
    PHP Code:
    <?php
    // ...
    if ($no_result) {
        
    header("HTTP/1.0 404 Not Found"true404);
    }
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    newphpcoder (07-02-2013)

  • #5
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    as a very simple example:
    PHP Code:
    <?php
    // ...
    if ($no_result) {
        
    header("HTTP/1.0 404 Not Found"true404);
    }
    how can I make put the value of process_name in $no_result??

    Thank you

  • #6
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,215
    Thanks
    12
    Thanked 338 Times in 334 Posts
    since I don’t know your PHP code–I don’t know. (besides that, what is process_name?)
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #7
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    since I don’t know your PHP code–I don’t know. (besides that, what is process_name?)
    process_name is list of process that can be displayed while the encode type letters.

  • #8
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    getting the process_list:

    PHP Code:
    <?php
    include "connection.php";
    $q strtolower($_GET["q"]);
    if (!
    $q) return;

    $sql "select process_id, process_name from process_list where process_name LIKE '$q%'";
    $rsd mysql_query($sql);
    while(
    $rs mysql_fetch_array($rsd)) {
        
    $pid $rs['process_id'];
        
    $pname $rs['process_name'];
        echo 
    "$pname|$pid\n";
    }
    ?>

  • #9
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,215
    Thanks
    12
    Thanked 338 Times in 334 Posts
    if you have an empty query (no match), the loop will not run, hence $pid & $pname will not exist. simply check for that to send the header.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    newphpcoder (07-03-2013)

  • #10
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts
    It works by this code:

    PHP Code:
    <?php
    ob_start
    ();
    include 
    "connection.php";
    $q strtolower($_GET["q"]);

    if (
    $q == '') {
       
    header("HTTP/1.0 404 Not Found"true404);   
    }

    //else (!$q) return;
    else{
    $sql "select process_id, process_name from process_list where process_name LIKE '$q%'";
    $rsd mysql_query($sql);

    $cnt mysql_num_rows($rsd);

        if(
    $cnt 0)
        {
            while(
    $rs mysql_fetch_array($rsd)) {
                
    $pid $rs['process_id'];
                
    $pname $rs['process_name'];
                echo 
    "$pname|$pid\n";
            }
            }
        else
        {
         
    header("HTTP/1.0 404 Not Found"true404);   
        }
    }

    ?>
    Thank you


  •  

    Posting Permissions

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