javascript - How to pass json string to webmethod c# ASP.NET -


im trying stringify javascript object , pass string parameter webmethod in code behind. can't work internal server error of 500 , stacktrace says value missing parameter.

here javascript code:

var json = json.stringify(javascriptobject);  // "{"foretagsnamn":"avector","bgfarg":"000000","textcolor":"fafafa","footerfarg":"ffffff","footercolor":"000000","footerlinkcolor":"050505","featuredbordercolor":"","hoverfarg":"12ebeb","rutfarg":"0d0d0d","selectedrutfarg":"","rutcolor":"ffffff","lankcolor":"","delamedsig":"1","personalsida":"0","startpagetitle":"","startpagedescription":"","googlemaps":"<iframe width=\"425\" height=\"350\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"https://maps.google.se/maps?f=q&amp;source=embed&amp;hl=sv&amp;geocode=&amp;q=avector ab&amp;aq=&amp;sll=56.225986,12.870827&amp;sspn=0.076248,0.154324&amp;ie=utf8&amp;hq=avector ab&amp;hnear=&amp;t=m&amp;cid=645910733081021950&amp;iwloc=a&amp;ll=56.224594,12.859229&amp;spn=0,0&amp;output=embed\"></iframe><br /><small><a href=\"https://maps.google.se/maps?f=q&amp;source=embed&amp;hl=sv&amp;geocode=&amp;q=avector ab&amp;aq=&amp;sll=56.225986,12.870827&amp;sspn=0.076248,0.154324&amp;ie=utf8&amp;hq=avector ab&amp;hnear=&amp;t=m&amp;cid=645910733081021950&amp;iwloc=a&amp;ll=56.224594,12.859229&amp;spn=0,0\" style=\"text-align:left\">visa större karta</a></small>","hittakartaurl":"http://www.hitta.se/avector ab/ängelholm/hxtp-4v1hg?vad=avector ab","enirokartaurl":"http://kartor.eniro.se/m/akkhi","ikoner":"2","email":"info@avector.com","adresssida":"1","shadowcolor":"ffffff","linecolor":"2b292b","menuhovericon":"välj bild från server","fontfamily":"verdana","supporttext":"support avector","captcha":true,"metakeywords":"","showsupportinfooter":true}"  $.ajax({     type: "post",     url: "post/installningar.aspx/updatera",     data: json,     contenttype: "application/json; charset=utf-8",     datatype: "json",     success: function (result) {          var resultasstring = result.d;         //_this.parent().siblings('.savedstatus').html(resultasstring);          if (resultasstring == "1") { // gick bra att spara.            alert("uppgifterna är sparade.");            document.location = document.location;         }         else {            $('#statustext').html("gick inte att spara uppgifterna.");         }       },     error: function (xhr, ajaxoptions, thrownerror) {      } }); 

and here webmethod:

[webmethod] public static string updatera(string json) { 

it feels i've tried i've found when searching google , here on so.

i've tried guide many refer to: http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

any ideas?

first need use

var json = json.stringify({obj:javascriptobject});

instead of

var json = json.stringify(javascriptobject);

then webmethod

[webmethod] public static string updatera(adata obj) {   // logic code  } 

now here adata class below

public class adata {          public string foretagsnamn  {get;set;}          public string bgfarg  {get;set;}          public string textcolor  {get;set;}          public string footerfarg  {get;set;}          public string email  {get;set;}        } 

so final code

jquery :

 var json = json.stringify({obj:javascriptobject});             $.ajax({                 type: "post",                 url: "post/installningar.aspx/updatera",                 data: jsondata,                 contenttype: "application/json; charset=utf-8",                 datatype: "json",                 success: onsuccess,                 error: onerrorcall             });              function onsuccess(response){              }              function onerrorcall(){              } 

code behind :

 public class adata {      public string foretagsnamn  {get;set;}     public string bgfarg  {get;set;}     public string textcolor  {get;set;}     public string footerfarg  {get;set;}     public string email  {get;set;} }   [webmethod] public static string updatera(adata obj) {    // logic code  } 

do check jquery ajax json example in asp.net


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -