must be missing something basic here. I am getting a 404 error calling a webmethod from jquery in an aspx page I'm running locally.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="empJquery.aspx.cs" Inherits="webApiOracle.empJquery" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<title>jquery emps</title>
<script src="Scripts/jquery-1.10.2.min.js"></script>
<link href="../Content/bootstrap.min.css" rel="stylesheet" />
<script type="text/javascript">
$(document).ready(function () {
getEmployees();
});
function getEmployees() {
jQuery.ajax({
url: 'empJquery.aspx/Test',
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function () {
alert("Start!!! ");
},
success: function (data) {
alert("a");
},
error: function (msg) { alert("Sorry!!! "); }
});
}
</script>
then in the code behind page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using webApiOracle.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace webApiOracle
{
public partial class empJquery : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public static string Test()
{
return "Success";
}
}
}
I'm getting a 404 error whenever I run I attempted changing url to /empJquery.aspx/Test I also tried localhost/empJQuery.aspx/Test and localhost:48784/empJquery.aspx/Test but I can't seem to get it. Do I need to add something to my web config? I'm running .net 4.5 thanks
Ok, I just found it my app is a hybrid MVC
, Web API
, ASPX
solution and my route configs were messing me up so I had to add:
routes.IgnoreRoute("{page}.aspx/{*webmethod}");