c# - Post <Li> Items with Json and Jquery to Web Method -


i trying pass <li> list web method using json , jquery. goal return list c# using session variable.my problem session return null. list never passes on web method. list:

<div>           <ol id="mycart">             <li>iphone</li>       <li>ipod</li>       <li>ipad</li>         </ol>           </div>  <input type="button" id = "btngetcart" value="get cart" /> 

the json script:

<script type="text/javascript">          $("#btngetcart").live("click", function () {              var items = $('.mycart').find('li').map(function() {   var item = { };     item.title = $(this).text();    return item; }); var json = json.stringify(items);              $.ajax({                  type: 'post',                  url: "webform4.aspx/getcart",                  data: "{json}",                  contenttype: 'application/json; charset=utf-8',                  datatype: 'json',                  success: function (r) {                    }              });          });      </script> 

the web method:

public class mycart         {             private string[] title;          }           [webmethod(enablesession = true)]         public static mycart getcart(mycart title)         {             httpcontext.current.session["j"] = title;             return title;           } 

error here :

html : <ol id="mycart">   has id attribute  var items = $('.mycart') //used class, not exists, try this:  var items = $('#mycart')  , change  data: "{json}", data: json, 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -