Duncan Palmer
Duncan Palmer

Reputation: 2913

Make a Ajax POST query to php script

so I have 9 check boxes which I want to post the data of to my php script and am stuck as to how I would do this? I have found this base:

$.ajax({
  type: "POST",
  url: "check.php",
  data: data,
  success: success,
  dataType: dataType
});

But I don't know how to go about setting that data, success and dataType of that function. I want to be able to send the states/values of my 9 checkboxes as the data and want to be able to call a javascript function which is parsing the output of the post request. This is what my check boxes look like.

<form id="myform">
    <input type="checkbox" id="1" name="1"/>
        <label for="1"><span>1</span></label>
    <input type="checkbox" id="2" name="2"/>
        <label for="2"><span>2</span></label>
    <input type="checkbox" id="3" name="3"/>
        <label for="3"><span>3</span></label>
    <input type="checkbox" id="4" name="4"/>
        <label for="4"><span>4</span></label>
    <input type="checkbox" id="5" name="5"/>
        <label for="5"><span>5</span></label>
    <input type="checkbox" id="6" name="6"/>
        <label for="6"><span>6</span></label>
    <input type="checkbox" id="7" name="7"/>
        <label for="7"><span>7</span></label>
    <input type="checkbox" id="8" name="8"/>
        <label for="8"><span>8</span></label>
    <input type="checkbox" id="9" name="9"/>
        <label for="9"><span>9</span></label>
</form>

Thanks.

Upvotes: 0

Views: 91

Answers (1)

Scary Wombat
Scary Wombat

Reputation: 44824

if the data is in a form you can serialize the form

var data = $('form').serialize();

see http://docs.jquery.com/Ajax/serialize

Upvotes: 1

Related Questions