|
-
Feb 8th, 2015, 08:41 PM
#1
Thread Starter
Member
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
-
Mar 9th, 2015, 08:46 PM
#2
Frenzied Member
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|