I get error Uncaught SyntaxError: Unexpected token
and here my code
my html
my javascript
<script type="text/javascript" src="<?php echo base_url().'assets/js/jquery.js'?>"></script>
<script type="text/javascript">
$(document).ready(function(){
show_data();
function show_data(){
$.ajax({
type:'ajax',
url:'<?php echo base_url()?>getdata',
async : false,
dataType : 'json'
success : function(data){
var html = '';
var i;
for(i=0; i<data.length; i++){
html += '<tr>'+
'<td>'+data[i].no+'</td>'+
'<td>'+data[i].name+'</td>'+
'</tr>';
}
$('#show_data').html(html);
}
});
};
});
</script>
get error message from chrome ERROR IMAGE someone can explain this error. Thanks
There are multiple reasons to occur this error, some reason are listed below:
1) Just some bad syntax, you're putting your POST data in the wrong spot.
So please check your Data first, which you post through Ajax.
2) jQuery doesn't support using POST and jsonp and the reason for that is very simple.
So in this type you have to use GET
method of ajax.
type: "GET"
you missed the semicolon at the end of your PHP tag inside script tag ; this is the firstmost error which is encountered when your page load you are facing error because of it.
<script type="text/javascript" src="<?php echo base_url().'assets/js/jquery.js'; ?>"></script>