-1

Been following some tutorials, as i'm learning C#, however was just attempting to make an ajax call to the server, i'm using my localhost.

As far as I can tell i'm doing its right, but it's obviously not. Maybe it my folder structure or just the name of the file.

Folder Structure

The Default.aspx file is at the project root Here is my ajax call

        $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "Default.aspx",
        dataType: "json",
        data: "{'FirstName':'test','LastName':'test1','City':'test3','EmailID':'test4'}",
        success: function (data) {
            console.log("Woo!");
        },
        error: function (result) {
            console.log("fail!");
        }
    });

I know eventually it will have to call a method within the file, but its not even finding it at the moment.

Thanks in advance, James

James Dale
  • 126
  • 1
  • 4
  • 11

1 Answers1

0

You can use controller Home and create the one action.

Example:

public ActionResult FirstAjax()
{
    return Json(true, JsonRequestBehavior.AllowGet);
}   

After that your jquery ajax is:

$.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: "Home/FirstAjax",
        dataType: "json",
        data: "",
        success: function (data) {
            console.log("Woo!");
        },
        error: function (result) {
            console.log("fail!");
        }
    });
Tbseven
  • 120
  • 8