Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to post two parameters in ajax j query one as formdata, another one object,

$.ajax({
           url: '../File/GetFileWithData',
           dataType: "json",
           cache: false,
           contentType: false,
           processData: false,
           data: form_data,
           type: "post",
           success: function (result) {

           }
       });

1. Am trying to send file with the help of formdata it works now.
But I wanna send two params like
var Obj={"Name": ""};

Obj.Name="Sehwag";

 $.ajax({
            url: '../File/GetFileWithData',
            dataType: "json",
            cache: false,
            contentType: false,
            processData: false,
            data: ({form_data:form_data, Object:Obj)}
            type: "post",
            success: function (result) {

            }
        });


Can i do something like this?


My Intention is just wanna post file in first param and textbox values in second param...
Posted
Updated 3-Feb-14 4:17am
v2
Comments
Is it showing any issue?
Vinoth R 4-Feb-14 4:06am    
Yeah if i post like this in controller values are coming as null...

If i post only FormData then it works fine...

1 solution

If you want to post some data to some other page using ajax than you can use Ajax Post method like below.

JavaScript
$.post("YourPageName.aspx",
                  {
                      Parameter1: document.getElementById('hidParameter1').value,
                      parameter2: document.getElementById('hidParameter2').value,
                      Parameter3: "Hello"
                  }



and you can get these paramters in YourpageName.aspx by
C#
Request.Form["Parameter1"]
and so on.


Hope it will help. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900