<div class="grid--cell fl1 lh-lg">
<div class="grid--cell fl1 lh-lg">
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, <a href="/help/reopen-questions">visit the help center</a>.
</div>
</div>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2013-04-13 00:15:46Z" class="relativetime">7 years ago</span>.</div>
</div>
</aside>
Problem
I am getting unexpected string error, yet I don't see anything wrong?..
This is my code:
$(document).ready(function() {
var search = $("#search");
$("#bla").click(function() {
if (search.val() != '') {
load();
$.post("ajax_search.php", { search : search.val()}, function(data) {
stop_load();
$(".result").html(data);
});
}
else
{
$(".result").html('');
}
});
$("#hover").hover(function() {
load();
$.post"ajax_search.php?type=sidebar", { sidebar : seach.val() }, function(get_data) {
stop_load();
$("sidebar").html(get_data);
}
});
function load() {
$('.load').html('<img src="http://i.imgur.com/ZoI4x5I.gif" />');
}
function stop_load(){
$('.load').html('');
}
});
Question
Basically the problem gets fixed after I remove the function that starts in the
$("#hover").hover(function() {
This is the error I am getting by the way:
Uncaught SyntaxError: Unexpected string :29
This is line 29:
});
Right before
$("#hover").hover(function() {
What is causing this? What I have done wrong? Thanks!
</div>
The syntax for your $.post
is incorrect. You're missing both an opening and closing parenthesis.
$("#hover").hover(function() {
load();
// v-- opening parathesis here
$.post("ajax_search.php?type=sidebar", { sidebar : seach.val() }, function(get_data) {
stop_load();
$("sidebar").html(get_data);
// v-- closing here
});
});
you are missing (
and )
$.post("ajax_search.php?type=sidebar", { sidebar : seach.val() }, function(get_data) {
stop_load();
$("sidebar").html(get_data);
});
Your post()
method is missing parens.
This:
$.post "ajax_search.php?type=sidebar", {
sidebar: seach.val()
},
Should be
$.post("ajax_search.php?type=sidebar", {
sidebar: seach.val()
}),
If you're not using an IDE that shows you JS errors, I suggest you check the console on whatever web browser you're using, or even pop your JS into a jsfiddle and click JSHint.
Just a suggestion for your future post:
Before posting any javascript/jQuery
code. Please do the folowing:
Visit the site jsfiddle.net
Then, paste your code in the javascript panel.
If it is a jQuery code, select the version from the Frameworks & Extensions box on right-side.
Then, click on the button at the top, named JSHint.
If there is any error, you will get to know them as red dots on right side.
Fix them and again click on JSHint.
Finally, if you get a message like below :
JSLint Valid! Good work! Your JavaScript code is perfectly valid.
Then run the code on your local machine once again and still if you are getting any error, then post your question on SO. No offence!