Jump to content

expected expression, got '.'


bravo14

Recommended Posts

Hi

 

I am using the javascript below to carry put an ajax call.

 

 

$('#tokenfield')
.on('tokenfield:createdtoken', function (e) {
$.ajax({
url: 'processProduct.php?action=addTag',
type: 'post',
data: {tag:e.attrs.value ,photo:83},
});
});

.tokenfield({

autocomplete: {

source: function (request, response) {

jQuery.get("processProduct.php?action=getTags", {

query: request.term

}, function (data) {

data = $.parseJSON(data);

response(data);

});

},

delay: 100

},

showAutocompleteOnFocus: true

});

When the page loads I get the following error in the console

 

yntaxError: expected expression, got '.'
[Learn More]
index.php:416

 

the unexpected '.' is the following line .tokenfield({

 

I am sure that the answer is really simple, but I can't figure it out at the moment, any hepp would be fantastic

Link to comment
Share on other sites

Do you think that '.tokenfield({' is valid javascript syntax?  

 

I also don't know why you are showing us a php error?  Is this javascript inside a php file? 

 

Also don't see why you are mixing the use of $ and jQuery...

 

At any rate, this is certainly more likely to be valid javascript...

 

$('#tokenfield').on('tokenfield:createdtoken', function (e) {
		$.ajax({
			url: 'processProduct.php?action=addTag',
			type: 'post',
			data: {tag:e.attrs.value ,photo:83},
		});
});

$('#tokenfield').autocomplete({
	source: function (request, response) {
			jQuery.get("processProduct.php?action=getTags", {
				query: request.term
			}, function (data) {
				data = $.parseJSON(data);
				response(data);
			});
		},
		delay: 100
	},
	showAutocompleteOnFocus: true
});
Link to comment
Share on other sites

There are issues with your code, no doubt, but what our friend above didn't mention is the reason you're getting the error is because you've got a semi colon at the end of line 8, even though you then try and concatenate another function call.

Remove that semi colon and your code shouldn't complain. Whether it works as you expect it to is what you'll need to test next

 

Denno

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.