笑故挽风 2015-08-22 22:09 采纳率: 100%
浏览 10

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 ;(

  • 写回答

2条回答 默认 最新

  • 胖鸭 2015-08-22 22:16
    关注

    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

    评论

报告相同问题?