0

The bit that sends the data out on a button click:

$.ajax({
    type: "POST",
    url: "<?php echo base_url(); ?>coformation/appoint/",
    data: {
            "director":director.attr('checked'),
            "shareholder":shareholder.attr('checked'),
            "secretary":secretary.attr('checked'),
            "firstname":firstname.attr('value'),
            "lastname":lastname.attr('value'),
            "birthday":birthday.attr('value'),
            "birthmonth":birthmonth.attr('value'),
            "birthyear":birthyear.attr('value'),
            "occupation":occupation.attr('value'),
            "nationality":nationality.attr('value'),
            "security1":security1.attr('value'),
            "securityletters1":securityletters1.attr('value'),
            "security2":security2.attr('value'),
            "securityletters2":securityletters2.attr('value'),
            "security3":security3.attr('value'),
            "securityletters3":securityletters3.attr('value'),
            "residentialaddress":residentialaddr.text(),
            "serviceaddress":serviceaddr.text()
          },
    success: function(response) { 
            alert(response.message);
    },
    dataType: "json"
});

But when i var_dump($_POST) in the target URL, it appears that this procedure sends out only 2 fields:

array (size=2)  'residentialaddress' => string 'XXX' (length=34)  'serviceaddress' => string '' (length=0)

What could be the problem?

2
  • Try to look at the POST request in your browser with a debug console (Firebug or Chrome console). Commented Jan 24, 2013 at 11:30
  • .attr('value') will only return value set in original html and only is value attribute is in original html, will not reflect user input. Use val()` for form controls Commented Jan 24, 2013 at 11:54

3 Answers 3

2

you are posting attributes there attr()..please go throu the link to see what attr actually does..

you can even try doing

console.log(director.attr('checked'));  //which you 'll notice that this is not you want

 "director":director.attr('checked'),....

this send either true or false..

that should be

 "director":director.val(),"shareholder":shareholder.val(),....

val() gives you the value of checked element if checkbox or radio .. text if textbox.... i think this is what you want

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

Comments

1

ofcourse only two of it will be sent:

data: {
        "director":director.attr('checked').val(),
        "shareholder":shareholder.attr('checked').val(),
        "secretary":secretary.attr('checked').val(),
        "firstname":firstname.val(),
        "lastname":lastname.val(),
        "birthday":birthday.val(),
        "birthmonth":birthmonth.val(),
        "birthyear":birthyear.val(),
        "occupation":occupation.val(),
        "nationality":nationality.val(),
        "security1":security1.val(),
        "securityletters1":securityletters1.val(),
        "security2":security2.val(),
        "securityletters2":securityletters2.val(),
        "security3":security3.val(),
        "securityletters3":securityletters3.val(),
        "residentialaddress":residentialaddr.text(), //<------it gets the text
        "serviceaddress":serviceaddr.text()          //<------it gets the text
      },

Your all other items are just creating objects not sending the values .val(), so you should append .val() after all others.

Comments

0

if the value of the key in the data object is undefined, it wont be sent example:

data: {
  'first': 'text',
  'second': undefined
}

second wont be sent

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.