Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submitting From jQuery to PHP

I have sent data to my jquery file and I tested the data string and everything is stored where it should be but when I post it to my php file all the variables are null. Can someone help me?

$(document).ready(function() {
  $(".button").click(function() {
  //$('.error').hide();
  var firstname = $("input#First_Name").val(); 
  var lastname = $("input#Last").val(); 
  var areacode = $("input#area_code").val(); 
  var phonenumber = $("input#Phone_Number").val(); 
  var emailaddress = $("input#emailaddress").val(); 
  var confirmemail = $("input#confirm_email").val(); 
  var password = $("input#Password_Input").val(); 
  var confirmpassword = $("input#ConfirmPassword").val(); 
  var streetaddress = $("input#StreetAddress_input").val(); 
  var streetaddress2 = $("input#StreetAddress2_input").val();
  var city = $("input#City_Input").val(); 
  var state = $("input#StateInput").val(); 
  var zipcode = $("input#ZipCode").val(); 
  var month = $("input#month_input").val(); 
  var day = $("input#day_input").val(); 
  var year = $("input#year_input").val(); 
  var services = $("input#services_input").val(); 
  var agreement = $("input#agreement").val(); 

  var dataString = 'firstname=' + firstname + '&lastname=' + lastname + '&areacode=' + areacode + '&phonenumber=' + phonenumber + '&emailaddress=' + emailaddress + '&confirmemail=' + confirmemail + '&password=' + password + '&streetaddress=' + streetaddress + '&streetaddress2=' + streetaddress2 + '&city=' + city + '&state=' + state + '&zipcode=' + zipcode + '&month=' + month + '&day=' + day + '&year=' + year + '&services=' + services + '&agreement=' + agreement; 
  alert(dataString); 
  $.ajax({
        type: "POST",
        url: "http://www.vectorcreditsolution.com/js/process.php",
        data: dataString,
            success: function() {
            alert("Yay it was sent"); 
    }
        });
        return false;
     });

and then my php file

<?php
    $FirstName = $_POST["firstname"];  
    $LastName = $_POST['lastname']; 
    $AreaCode = $_POST['areacode']; 
    $PhoneNumber = $_POST['phonenumber']; 
    $EmailAddress = $_POST['emailaddress']; 
    $Password = $_POST['password']; 
    $StreetAddress = $_POST['streetaddress']; 
    $StreetAddress2 = $_POST['streetaddress2']; 
    $City= $_POST['city']; 
    $State = $_POST['state']; 
    $ZipCode = $_POST['zipcode']; 
    $Month = $_POST['month']; 
    $Day = $_POST['day']; 
    $Year= $_POST['year'];
    $Service=$_POST['services']; 

    var_dump($_POST["firstname"]); 
    var_dump($_POST['firstname']); 
    var_dump($_POST[firstname]); 
like image 334
user1154295 Avatar asked Jan 17 '12 15:01

user1154295


1 Answers

Try posting data as a Javascript dictionary, not as a big string:

$.ajax({
    // ...
    data: {
        firstname: firstname,
        lastname: lastname,
        // etc.
    }
});
like image 176
millimoose Avatar answered Sep 23 '22 06:09

millimoose