Jump to content

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
https://forums.phpfreaks.com/topic/305908-expected-expression-got/
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
});

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.