Results 1 to 2 of 2

Thread: Simple dummy action for learning Ajax

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    36

    Simple dummy action for learning Ajax

    Folks,

    To learn Ajax call, I'd like to create a very simple action. It wouldn't take any data, or return any data, it would only return success code. So far, I wrote this:

    Code:
        public class ProjectController : Controller
        {
    
            // AJAX: /Project/Save
            public ActionResult Save()
            {
                System.Threading.Thread.Sleep(600);     // A bit of latency to make the Ajax call more visible to human eye.
                return new EmptyResult();
            }
        }
    But I'm having problems with calling this from jQuery. The calling code:

    Code:
        $("button[name='btnSaveProject']").click(function () {
            console.log("make ajax call");
            $.ajax({
                url: "/Project/Save",
                type: "GET",
                timeout: 8000,
                cache: false
            }).done(function () {
                console.log("ajax call successful");
            }).fail(function (jqXHR, textStatus) {
                console.log("something went awry. " + textStatus);
            });
        });
    Unfortunately, .fail() gets called back.

    Any suggestion, insight or reference is really appreciated!

    Cheers,
    - Nick

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Simple dummy action for learning Ajax

    I'm not sure, but maybe the /Project/Save needs to have the specific extension in the url as well? I'm not sure if the default dataType is 'text' or not but you could try specifying that as well:

    Code:
    $.ajax({
    url: '/Project/Save.aspx',
    type: 'get',
    dataType: 'text',
    timeout: 8000,
    cache: false,
    success: function(data){
         console.log("ajax call successful: " + data);
    },
    error: function(jqXHR, textStatus, errorThrown){
     console.log("something went awry. " + textStatus);
    }
    });
    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width