1

I am having a problem sending the dataString to the server. Aparently it is not pulling the values correctly from the form. Below is my jquery and my php.

$(document).ready(function() {  
    $("#submitForm").live('click', function() {
        updateUserInfo();
    });

var birthdate = $("#birthdate");
var sex = $("#sex");
var interestedIn = $("#interestedIn");
var relationshipStatus = $("#relationshipStatus");
var knownLanguages = $("#knownLanguages");
var religiousViews = $("#religiousViews");
var politicalViews = $("#politicalViews");
var aboutMe = $("#aboutMe");
var mobilePhone = $("#mobilePhone");
var neighborhood = $("#neighborhood");
var website = $("#website");
var email = $("#email");

var dataString = birthdate + sex + interestedIn + relationshipStatus + knownLanguages + politicalViews + aboutMe + mobilePhone + neighborhood + website + email;

function updateUserInfo() {
    jQuery.ajax({
        type: "POST",
        dataType: "JSON",
        url: "<?=base_url()?>index.php/regUserDash/updateUserInfo",
        data: dataString,
        json: {userInfoUpdated: true},
        success: function(data) {
        if(data.userInfoUpdated == true) {
            alert("hello");
        }
      }
   });
}
});

My PHP:

 public function updateUserInfo() {
        $userid = $this->session->userdata('userid');
        $birthdate = $this->input->post("birthdate");
        $sex = $this->input->post("sex");
        $interestedIn = $this->input->post("interestedIn");
        $relationshipStatus = $this->input->post("relationshipStatus");
        $languages = $this->input->post("languages");
        $religiousViews = $this->input->post("religiousViews");
        $politicalViews = $this->input->post("politicalViews");
        $aboutMe = $this->input->post("aboutMe");
        $mobilePhone = $this->input->post("mobilePhone");
        $neighborhood = $this->input->post("neighborhood");
        $websites = $this->input->post("websites");
        $email = $this->input->post("email");

        $this->db->query("INSERT IGNORE INTO user_info (birthdate, sex, interestedIn, relationshipStatus, Languages, religiousViews, politicalViews, aboutMe, mobilePhone, neighborhood, websites, email, userid)
                          VALUES('{$birthdate}', '{$sex}', {$relationshipStatus}', '{$languages}, {$religiousViews}', '{$politicalViews}', {$aboutMe}', '{$mobilePhone}' {$neighborhood}', '{$websites}', {$email}', '{$userid}')");

        echo json_encode(array('userInfoUpdated' => true));
    }

2 Answers 2

1

Use .val() to get the value of the element. And change your dataString to:

var dataString = {'birthdate' : birthdate, 'sex' : sex, 'interestedIn' : interestedIn, 'relationshipStatus' : relationshipStatus, 'knownLanguages' : knownLanguages, 'politicalViews' : politicalViews, 'aboutMe' : aboutMe, 'mobilePhone' : mobilePhone, 'neighborhood' : neighborhood, 'website' : website, 'email' : email};

From api.jquery.com: jQuery.ajax data

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

7 Comments

Sorry for the late reply, but it is still not working. Here is my error: i50.tinypic.com/2bp750.png. If you notice it isn't even passing through json.
Everything is running correctly. This is odd. here is my PHP if that might help any: pastebin.com/R7tjfkDx.
@MichaelGrigsby check Network tab in Chrome and look for the request which JQuery sends. Is it there? If yes, look through request headers and find Form data. What is there?
Only the default values from the select boxes are being passed
@MichaelGrigsby Got it, select boxes, thats what causing the problem. E.g. $('#sex') is a select box, and to obtain selected value you should use :selected. var sex = $('#sex :selected').val()
|
0

The code $("#birthdate"); will return an element with id #birthdate but not it's value. use val function to get the value in it. like var birthdate = $("#birthdate").val();

Comments

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.