gerkintrigg Posted March 16, 2012 Share Posted March 16, 2012 Hello. I think I have worked out where my problem lies, but have no clue how to fix it. I'm posting the first name, surname and email to a newsletter signup script I found online. The original script only used the email address, but I wanted to make it a little more dynamic (a bit like aweber in that it can accept [fname] and replace it with the name from the database). Everything works except actually inserting the fname and sname variables into the database. (I was testing it using the SQL back end, originally). I have tracked the issue to a Javascript snippet which originally said this: data: 'email=' + $('#email').val(), // data to post Thinking logically (or not), i changed it to this: data: 'email=' + $('#email').val()+ 'fname=' + $('#fname').val()+ 'sname=' + $('#sname').val(), // data to post This was initially just to prove to myself that the data is there and being passed to the script... it is, but it currently outputs like this: email@email.comfname=firstnamesname=surname Could someone please let me know what I'm doing wrong. I'm fine with PHP, but to say that I "muddle through" the javascript aspect is probably about right. Quote Link to comment https://forums.phpfreaks.com/topic/259047-posting-forms-to-ajax-script/ Share on other sites More sharing options...
trq Posted March 16, 2012 Share Posted March 16, 2012 It needs to be concatenated together with & A cleaner method is to use an object. data: { email: $('#email').val(), fname: $('#fname').val(), sname: $('#sname').val() } Quote Link to comment https://forums.phpfreaks.com/topic/259047-posting-forms-to-ajax-script/#findComment-1328003 Share on other sites More sharing options...
gerkintrigg Posted March 16, 2012 Author Share Posted March 16, 2012 thorpe, As always, I bow to your superior intellect. It works great. The final script can be seen at http://ghostlypublishing.co.uk/members/admin/mailing_list/admin/ All the best, gerkintrigg Quote Link to comment https://forums.phpfreaks.com/topic/259047-posting-forms-to-ajax-script/#findComment-1328040 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.