0

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

2 Answers 2

2

if you don't mind then use jquery $.get function.

Sign up to request clarification or add additional context in comments.

3 Comments

what is jquery, schould i install this seperatly?
MVC is kind of build with jQuery in mind (they jQuery with it, and in MVC3 the ajax stuff is build upon jQuery)
Knowledge of jQuery or any other kind of javascript framework is kind of a must in modern day website developed. Go to jquery.com and follow the tutorials.
1

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 :)

2 Comments

is $.ajax in <script type="text/javascript"> tags?
Yes. As said above you should read the documentation and look at jQuery examples. It really is easy. Make sure you look at the $(document).ready() part api.jquery.com/ready - it's important.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.