Question: I have several static files. There is no database involved. These files are used for several different purposes. Code snippets, different international languages etc. How do I go about sanitizing input for a search query if the only thing I am doing is something like

```
$searchQuery = $_GET['q'];
$a = 'How are you?';
if (strpos($a, $searchQuery) !== false) {
    echo 'true';
}

```

which is recursively used on each file.

Is sanitization required in this case?

Answer: 
This Type of AJAX Call dataType is not required

Remove 

```
dataType: 'json'

```

Use like

```
<script type="text/javascript">
function gethtml(){
    var url = "<?php echo base_url();?>home/ajax_test";
    alert(""+url);
    $.ajax({
        url: url,
        type: 'POST',
        success: function(data){
            alert("ajax success");
        }
    });
}
</script>

```
Try on view

```
<button id="btn">ajax Test</button>

<script type="text/javascript">
$('#btn').on('click', function(e) {

    // e.preventDefault(); Not sure if you need it.

    $.ajax({
        url:"<?php echo base_url('home/ajax_test');?>",
        type: 'POST',
        dataType: 'json',
        // data: {
        // someinput: $('#someinput').val()
        //},
        success: function(data){
            alert(data['test']);
        }
    });
});

</script>

```

On controller you can use the output class also.

```
public function ajax_test() {

    $json['test'] =  "return from ajax";

    $this->output->set_content_type('application/json');
    $this->output->set_output(json_encode($json));
}

```