0

ı need to send data one is array another is single data.

var img=$('#image').val(); // image name

var formdatas=($(this).serialize()); // data from form, including to many data

data:formdatas, //legal
data:{f:formdatas,r:img}, //legal but formdatas is an array ı cant send it like this

but ı need something like this.

data:{formdatas,r:img}, // this is not working

and this is my complete code, ı just need to send 2 different data.

$('#lastikekle').submit(function() {

    var resim=$('#resim').val();

    var formverileri=($(this).serialize());

    $.ajax({
              type:"POST",          
              url: "lastikekle.php",
              data:{formverileri,r:resim}, ????
              success: function(result){

                $( "#dialog" ).dialog();
                $("#dialog").html(result);
                                        }   
        });


    });
1
  • serialize() returns a string, not an array. Commented Aug 22, 2012 at 9:31

1 Answer 1

2

Try: (.serialize returns a string)

data: formdatas+'&r='+encodeURIComponent(img)

Edit: or you could use serializeArray

$('#lastikekle').submit(function () {
    var resim = $('#resim').val();
    var formverileri = $(this).serializeArray();
    formverileri.r = resim;
    $.ajax({
        type: "POST",
        url: "lastikekle.php",
        data: formverileri,
        success : function (result) {
            $("#dialog").dialog();
            $("#dialog").html(result);
        }
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

I used to solve issues like that. But I noticed encoding issues with characters like éàè and so on. But if you pass a 'non-string' value to the ajax data, the encoding issues didn't occur. Maybe less important in languages where these characters aren't used, but it did put me off using strings as data.
Perfect solution :) I don't blame people for no knowing the encoding issues, because most languages don't really rely on accented characters. I really feel sorry for french/scandinavian programmers at times, encoding issues are downright annoying.

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.