开发者

how can i send data to server

I am having ASP.NET MVC application in which i have to send data from client browser to the se开发者_运维百科rver. Client browser means that data is present in javascript function (calculated) now what should i use to send this data to server . Before MVC, in my old application i was using Web Methods Please advice


you can use AJAX, e.g. in jQuery:

$.post(url, { name: "value"}, callback }


Say you have a controller called HomeController and a actionResult called Index that loads up the index page and another actionResult called SaveData(string data)

Now in the index page you would write your script

$(function()
{
   var data = // get data.
   $.post('SaveData',{ sendingData: data}, function(response)
   {
          alert(response);
   });
});

public ActionResult SaveData(string sendingData)
{
   // do somethig with the data  
}

Thats all to it. No more making generic handlers or a webserver for each ajax request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜