JSON.stringify Post \u0027salesmain\u0027 error

JSON.stringify Post \u0027salesmain\u0027 error

tanersttanerst Posts: 4Questions: 0Answers: 0
edited October 2013 in DataTables 1.9
Hello ,


stringify post asp.net \u0027salesmain\u0027 error ,where you got it wrong !

Thansk for help.




[code]




// This function is used fro
// delete selected row from Detail Table
// set deleted item to Edit text Boxes
function DeleteRow() {

// Here I have used DataTables.TableTools plugin for getting selected row items
var oTT = TableTools.fnGetInstance('tbl'); // Get Table instance
var sRow = oTT.fnGetSelected(); // Get Selected Item From Table


// Set deleted row item to editable text boxes
$('#Sokkodu').val($.trim(sRow[0].cells[0].innerHTML.toString()));
$('#Miktar').val(jQuery.trim(sRow[0].cells[1].innerHTML.toString()));
$('#Tutar').val($.trim(sRow[0].cells[2].innerHTML.toString()));


$('.tbl').dataTable().fnDeleteRow(sRow[0]);

}



$(document).ready(function () {

// here i have used datatables.js (jQuery Data Table)
$('.tbl').dataTable({
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"aButtons": [],
"sRowSelect": "single"
},
"bLengthChange": false,
"bFilter": false,
"bSort": false,
"bInfo": false
});

$('#SalesDate').datepicker();

var oTable = $('.tbl').dataTable();
});




// this function is used to add item to list table
function Add() {

// Adding item to table
$('.tbl').dataTable().fnAddData([$('#Stokkodu').val(), $('#Miktar').val(), $('#Tutar').val()]);

// Making Editable text empty
$('#Stokkodu').val("")
$('#Miktar').val("")
$('#Tutar').val("")


}



//This function is used for sending data(JSON Data) to SalesController
function Sales_save() {
// Step 1: Read View Data and Create JSON Object

// Creating SalesSub Json Object
var salessub = { "sip_RECno": "", "Stokodu": "", "Miktar": "", "Tutar": "" };


// Creating SalesMain Json Object
var salesmain = { "sip_RECno": "", "Evraknoseri": "", "Evraknosira": "", "Carikod": "", "SalesSubs": [] };

// Set Sales Main Value
salesmain.sip_RECno = $("#sip_RECno").val();
salesmain.Evraknoseri = $("#Evraknoseri").val();
salesmain.Evraknosira = $("#Evraknosira").val();
salesmain.Carikod = $("#Carikod").val();


// Getting Table Data from where we will fetch Sales Sub Record
var oTable = $('.tbl').dataTable().fnGetData();



for (var i = 0; i < oTable.length; i++) {

// IF This view is for edit then it will read SalesId from Hidden field
if ($('h2').text() == "Edit") {
salessub.sip_RECno = $('#sip_RECno').val();
}
else {
salessub.sip_RECno = 0;
}

// Set SalesSub individual Values
salessub.Stokkodu = oTable[i][0];
salessub.Miktar = oTable[i][1];
salessub.Tutar = oTable[i][2];
// adding to SalesMain.SalesSub List Item
salesmain.SalesSubs.push(salessub);
salessub = { "Stokkodu": "", "Miktar": "", "Tutar": "" };


}


// Set 2: Ajax Post
// Here i have used ajax post for saving/updating information
$.ajax({
url: 'SiparisE.aspx/SetOrder',
data: JSON.stringify(salesmain),
type: 'POST',
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (result) {

if (result.Success == "1") {
window.location.href = "./Index.aspx";
}
else {
alert(result.ex);
}
}
});


}




[/code]





[code]

[System.Web.Services.WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]

public static string SetOrder(SalesMain salesmain)
{
SqlConnection cn = new SqlConnection("Data Source=******;Initial Catalog=******;Persist Security Info=True;User ID=****;Password=*********");
SqlCommand cmd = new SqlCommand("insert into SIPARISLER VALUES (@sip_evrakno_seri,_sip_evrakno_sira,@Stokkod)",cn);

cmd.Parameters.AddWithValue("@sip_evrakno_seri",salesmain.Evraknoseri);
cmd.Parameters.AddWithValue("@sip_evrakno_sira",salesmain.Evraknosira);
cmd.Parameters.AddWithValue("@sip_stok_kod",salesmain.SalesSubs);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();

return "ok";
}

[/code]

Replies

  • tanersttanerst Posts: 4Questions: 0Answers: 0
    any help !!
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    What is the JSON returned by the server? Please link to a test case as noted in the forum rules.

    Allan
  • tanersttanerst Posts: 4Questions: 0Answers: 0
    edited October 2013
    [code]
    {"Message": "Invalid web service call, \ u0027salesmain \ u0027 parameter value is missing.", "StackTrace": "You're System.Web.Script.Services.WebServiceMethodData.CallMethod (Object target, IDictionary` 2 parameters) \ r \ n're System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams (Object target, IDictionary `2 parameters) \ r \ n location: System.Web.Script.Services.RestHandler.InvokeMethod (HttpContext context, WebServiceMethodData methodData, IDictionary` 2 rawParams) \ r \ n location: System.Web.Script.Services.RestHandler.ExecuteWebServiceCall (HttpContext context, WebServiceMethodData methodData) "," ExceptionType ":" System.InvalidOperationException "}
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Looks like an error in your script. I'm afraid we can't help with that here, as its not Javascript. Probably best to ask in SO or similar.

    Allan
  • tanersttanerst Posts: 4Questions: 0Answers: 0
    change to $ajax data JSON.stringify({ salesmain: salesmain }), no problem :) thanks.
This discussion has been closed.