samedi 25 avril 2015

checkbox values not passed through JSON

It was working fine. I'm just surprise to find all of a sudden, the checkbox values are not passed through in $_POST via json. I can't seem to understand why. Hopefully someone could help me with this.Below is the checkbox in php.

$subjects_id= $row['subid'];

<td><input type="checkbox" name="sub['.$subjects_id.']" id="sub" value="">     </td>';

JSON

$("document").ready(function(){
  $(".form").submit(function(){
    var data = {
      "action": "test"
    };
    data = $(this).serialize() + "&" + $.param(data);
    $.ajax({
      type: "POST",
      dataType: "json",
      url: "response.php", //Relative or absolute path to response.php file
      data: data,
      success: function(data) {
        $(".the-return").html(
          "Favorite beverage: " + data["favorite_beverage"] + "<br />Favorite restaurant: " + data["favorite_restaurant"] + "<br />Gender: " + data["gender"] + "<br />JSON: " + data["json"]
        );

        alert("Form submitted successfully.\nReturned json: " + data["json"]);
      }
    });
    return false;
  });
});

I'm sure there's no problem with JSON. But I doubt on my php for the checkbox. In the JSON key-value pairs, the checkbox is not passed although it's checked!




Aucun commentaire:

Enregistrer un commentaire