mvasco mvasco - 2 months ago 26
Javascript Question

Uncaught SyntaxError: Invalid or unexpected token in JavaScript

I am getting this error message at the console for line:

var dataString = \'search=\'+ searchid;


at following script:

$(function(){
$(".search").keyup(function()
{
var searchid = $(this).val();
var dataString = \'search=\'+ searchid;
if(searchid!=\'\')
{
$.ajax({
type: "POST",
url: "classes/search.php",
data: dataString,
cache: false,
success: function(html)
{
$("#result").html(html).show();
}
});
}return false;
});


What is wrong there?

Answer

There is no need to escape quotes in this situation:

var dataString = 'search=' + searchid;

And as commented the next line also has issue. Remove the slashes.

Comments