Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mixing javascript and php variables in ajax

I have a pretty basic jQuery ajax thing happening, but I want to mix form data that is retrieved by JS with some PHP variables and have them all sent as part of the ajax GET. Should this work?:

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 echo the variables back, they're empty.

UPDATE

After checking the source as suggested, it comes out like this:

data:   longform + "&domain=example.com&useragent=Mozilla/5.0
like image 427
Gary Avatar asked Nov 05 '22 06:11

Gary


1 Answers

You need to add an ampersand (&) before domain=. Otherwise, it should be fine.

Do a View Source on the page and make sure the javascript string looks correct as well.

like image 127
simshaun Avatar answered Nov 09 '22 02:11

simshaun