简体   繁体   中英

asp.net mvc - how to write ajax request in javascript

i would like to update follow div with ajax request written in javascript method.

asp.mvc view:

<div id="feed" onload="GetFeeds()">
            <span id="feeds" runat="server">
                    <%= Model.Feeds %>
            </span>
        </div>

what schould i do in javasript?:

<script type="text/javascript">

   // some AJAX Request with 'feed' Update, but HOW??
   document.getElementById('feed');

    function GetFeeds() { 
    // need to call method from HomeModel.cs GetAllFeeds()??
    // or i should to write hole methode here?
    }

</script>

it schould work without any controller action. method for FeedUpdating is written in HomeModel.cs / GetAllFeeds() and it works. I need just call it from javascript

如果您不介意,则使用jquery $ .get函数。

Highly recommend using jQuery

$.ajax( 
   url: 'http://localhost/feeds/feed1',
   type:'GET',
   dataType: 'json',
   success: function(data) { 
         //Process data
   },
   error: function(error) { }
);

It does all the heavy lifting for you and is tested on many more browsers than you will be able to test on in your lifetime :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM