Question: I want to fetch that through model 

```
SELECT `id`, `name`, `visits`, `shortdes`, `photo` FROM `products`
         WHERE  `name` LIKE '$word'
         OR `shortdes` LIKE '$word' ANd  `valid` = 1 ORDER BY `id` DESC

```

I used that, but it returned false

```
$this->db->order_by('id', 'desc');
$this->db->like('name', $word);
$this->db->or_like('shortdes', $word);
$this->db->where('valid', 1);
$this->db->select('id, name, visits, shortdes, photo');
$query = $this->db->get('products');

```

What can i use?

Answer: 
You are **redefining** the variable **data** in your else block(more specific scope) and hence the global scope variable will still be undefined.
Change var data = new tempdata(); to

```
data = new tempdata(); //In the else block

```

So, now your ajax call should look like:

```
$.ajax({
          url: 'getmetadata.php',
          type: "POST",
          data: entereddata,
          dataType: "json",
          timeout: (7000), //wait 7 seconds

            error: function(data) 
            {   
            // handle errors
            if(data)
            {

            // Do nothing error message will be issued from the data object 
            }else{

                /******************NOTE THE CHANGE HERE********************/
                data = { 

                    errortitle:"Error title",
                    errormessage:"Error text"
                };

            };  

            // issue error message
            runDialogue(data.errortitle,data.errormessage);

            }, //ERROR

            success: function(data) 
            {
            }; // SUCCESS
    }); // AJAX

```
Javascript throws an error on undefined references; you can't test existence just using the object. You can use the typeof operator to test whether the data exists, or instead whether it is of type "object".

For example:

```
if (typeof data === "undefined")
{
   // You don't really need a closure for this...
   errordata = {'errortitle'   : 'Error Title',
                'errormessage' : 'Error Message'};

 runDialogue(data.errortitle, data.errormessage);
}

```