Your JS code:
var data = 'val1=<?php echo $values1; ?>&val2=<?php echo $values2; ?>';
Gives a Javascript syntax error if one or more of your PHP variables $values1 OR $values2 contain a single quotation mark in them ' .
Make sure your PHP variable does not contain single quotes in them by replacing all single quotes with something else, otherwise use double quotes " to create JS var as follows:
var data = "val1=<?php echo $values1; ?>&val2=<?php echo $values2; ?>";
The provided PHP variables do not contain double quotes.
source share