Post an object as data using Jquery Ajax

后端 未结 6 2096
栀梦
栀梦 2020-11-28 10:24

My code that I tried is as follows:

var dataO = new Object();
dataO.numberId = 1;
dataO.companyId = 531;

$.ajax({
 type: \"POST\",
 url: \"TelephoneNumbers.         


        
6条回答
  •  余生分开走
    2020-11-28 11:12

    Just pass the object as is. Note you can create the object as follows

    var data0 = {numberId: "1", companyId : "531"};
    
    $.ajax({
     type: "POST",
     url: "TelephoneNumbers.aspx/DeleteNumber",
     data: dataO,
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     success: function(msg) {
     alert('In Ajax');
     }
    });
    

    UPDATE seems an odd issue with the serializer, maybe it is expecting a string, out of interest can you try the following.

    data: "{'numberId':'1', 'companyId ':'531'}",

提交回复
热议问题