Skip to Content
Introducing .NET 4.0: with Visual Studio 2010
book

Introducing .NET 4.0: with Visual Studio 2010

by Alex Mackey
February 2010
Beginner content levelBeginner
400 pages
11h 13m
English
Apress
Content preview from Introducing .NET 4.0: with Visual Studio 2010

12.10. AJAX Methods

It is very common for performance optimization to need to retrieve data or code from an external source after a page is loaded. jQuery makes this very easy.

12.10.1. Load and Run JavaScript File

The following code loads an external JavaScript file called test.js and then executes it:

$.ajax({
    type: "GET",
    url: "test.js",
    dataType: "script"
});

The test.js file consists of just the following line:

alert('hello');

12.10.2. Submitting Data

You often need to submit data to another web page. You can easily do this with the following code:

$.ajax({
    type: "POST",
    url: "myForm.aspx",
    data: "firstname=Alex&lastname=Mackey",
    success:
    function() {
        alert("form submitted");
    }
});

You will use this functionality in the ASP.NET MVC example ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 3.5 For Dummies®

ASP.NET 3.5 For Dummies®

Ken Cox
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9781430224556Purchase book