- 1 year ago 97
Ajax Question

How to POST two variable using ajax for save the data

I want to POST two variables. One is a JSON string and another one is a textbox value I am using C# for SQL server connection. Can anyone please check what is wrong in my code.

var myjsonstring = JSON.stringify(myjson);
var filename = $("#fname").val();

type: "POST",
url: "http://localhost/name/Service/SaveData",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify({
jsonobject: myjsonstring,filename
success: function (data) {

error: function () {

Answer Source

You can pass an normal object to data of $.ajax:

data: {
    myjsonstring: myjsonstring,
    filename: filename
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download