this code here is suppose to call a file that will in return return data for fill in a form but i am getting this error (in the code) and i do not know why.
dropdown.bind('change', function(){
$post.('backgroundScript.php',
Uncaught SyntaxError: Unexpected token ( - this is the error im getting
{
first: dropdown.val()
},
function(response) {
$('#first').val(response.first);
$('#last').val(response.last);
// Repeat for all of your form fields
},
'json'
);
});
it you would give me a hand i would appreciate it :)
asked Aug 7, 2012 at 6:17
user1578456
2 Answers 2
Put the . before post instead of after it, thx to Mihai Stancu for spotting that.
dropdown.bind('change', function(){
$.post('backgroundScript.php',
{
first: dropdown.val()
},
function(response) {
$('#first').val(response.first);
$('#last').val(response.last);
// Repeat for all of your form fields
},
'json'
);
});
answered Aug 7, 2012 at 6:20
Willem D'Haeseleer
20.3k10 gold badges69 silver badges104 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Mihai Stancu
$post is not going to work either, It's going to show another error regarding
$post as an undefined variable and not a function. The jQuery object is aliased as $ so accessing a method on the jQuery object looks something like this jQuery.post() or $.post().Willem D'Haeseleer
that might be true, but it will solve your syntax error, if $post isn't defined then you will have to look into why that is.
Mihai Stancu
$.post is a method of the jQuery object which he seems to be using (due to the order and type of parameters specified to the function itself).
Try using "$.post( instead of $post.(
Tiago Sippert
1,3307 gold badges24 silver badges33 bronze badges
answered Aug 7, 2012 at 6:24
Shabnam K
1,5821 gold badge9 silver badges10 bronze badges
4 Comments
Ahsan Khurshid
The jQuery object is aliased as $ so accessing a method on the jQuery object looks something like this jQuery.post() or $.post()
Mihai Stancu
@A.K OP did not mention jQuery, it's natural that JavaScript devs that do not know jQuery reach this page and try to answer as best they can. At this point we can only assume it was jQuery due to the look and feel of the parameters given to the $.post function. We may be wrong it may be some other framework.
Ahsan Khurshid
He also didn't mentioned ajax. And in simple javascript
$ has no meaning.Mihai Stancu
Yes it does, it can be a variable name ;-)
default