Jquery autocomplete on select event

前端 未结 2 441
粉色の甜心
粉色の甜心 2020-12-15 06:47

I am using jQuery autocomplete and its working fine, now I want to store a variable in session from jQuery when following condition occurs.

When someone types any w

2条回答
  •  情歌与酒
    2020-12-15 07:31

    Well, if you want to store in session using asp.net mvc3 then do the following

    $(".autosearch-smart").autocomplete('Home/GetCompanyNames', {
        minChars: 1,
        width: 402,
        matchContains: "word",
        autoFill: true,
        select: function (event, ui) {   //must be cleared with function parameter
            //alert(ui.item.label);  //will show you the selected item
    
           $.ajax({
              type: 'POST',
              url: '/Controller/Action1',  //whatever any url
              data: {label: ui.item.label},
              success: function(message) { if(message.data == true) ... else ... },
              dataType: 'json'
           });
    
        }
    
    });
    

    and controller

    [HttpPost]
      public JsonResult Action1( string label ) {
    
         this.Session["AnyValue"] = label;
    
         return Json( new {
            data = true
         }, JsonRequestBehavior.AllowGet );
      }
    

提交回复
热议问题