5

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
1

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Everything should be fine if you add PHP's 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 could be caused by your data (i.e. if you have backslashes or other special chars in there).

Comments

0

I would rather put all data in hidden inputs, and then serialize all in once.

Tom

1 Comment

Yes, I decided to go this route.. turns out my main problem was a dumb mistake on my part.. missed a $_GET in the php >_>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.