Ajax发布数据问题

Hi besides a jquery function, i want to submit the input formfield of #dropdownbox1 with the ajax post too...please take a look:

The function foo.crop will return an object that contains the width, height, and image string + data type:

$.ajax({
        type: "post",
        url: "process.php",
        data: foo.crop(846, 846, 'png') 
    })
    .done(function(data) {

            // do stuff after image is saved
 alert( "Okay!" );
    });

process.php recieving the variables:

if($_SERVER['REQUEST_METHOD'] == "POST") {



    $img = str_replace('data:image/'.$_POST['type'].';base64,', '', $_POST['string']);
    $img = str_replace(' ', '+', $img);

how can i add the #dropdown value to the data to send it to process.php ?

maybe if it helps, here is the crop function with the returns:

this.crop = function(width, height, type) {

        ....

            return {
                width: width,
                height: height,
                type: type || 'png',
                string: canvas.toDataURL("image/" + type || 'png'),
            };

        };

please help im quiet new to jquery and i need to get this script work!

TRIED THAT:

var data = {
    imageData: foo.crop(846, 846, 'png'),
    dropdown: $("#dropdownbox1").val()
};
$.ajax({
 type: "post",
        url: "process.php",
        data: data
});

but it didnt work ;(

In the data attribute, just pass an object where each key is the name you want to use on the server and the values are the values from your form

var data = {
    imageData: image,
    dropdown: $("#dropdownbox1").val()
};
$.ajax({
 type: "post",
        url: "process.php",
        data: data
});

See here

You can pass 2 parameters to the data attribute like this

$.ajax({
        type: "post",
        url: "process.php",
        data: {
                "image":foo.crop(846, 846, 'png'),
                "select": $("#dropdownbox1").val()
          }
    })
    .done(function(data) {
            // do stuff after image is saved
 alert( "Okay!" );
    });

You can then access these on your process.php page. Print the post array as print_r($_POST) to ensure you get the expected values.