Mixing javascript and php variables in ajax

I have a pretty simple jQuery ajax thing, but I want to mix the form data that JS retrieves with some PHP variables, and they all submit as part of the ajax GET. If it works ?:

var longform = $("input:text").serialize(); 
$.ajax({
    url:    'actions/create.php',
    data:   longform + "domain=<?php echo $domain; ?>&useragent=<?php echo $useragent; ?>&ip=<?php echo $ip; ?>&cookieuser=<?php echo $cookieuser; ?>",

Currently, when create.php tries to throw variables back, they are empty.

UPDATE

After checking the source, as suggested, it looks like this:

data:   longform + "&domain=example.com&useragent=Mozilla/5.0
+5
source share
3 answers

I would rather put all the data in hidden inputs and then serialize everything in one go.

Tom

0
source

You need to add an ampersand (&) in front of the = domain. Otherwise, it should be good.

View View , javascript .

+1

Everything should be fine if you add a PHP urlencode()function :

"domain=<?php echo urlencode($domain); ?>&useragent=<?php echo urlencode($useragent); ?>&ip=<?php echo urlencode($ip); ?>&cookieuser=<?php echo urlencode($cookieuser); ?>"

This should prevent syntax errors that might be caused by your data (i.e. if you have backslashes or other special characters).

+1
source

All Articles