1

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

3
  • Your port number must match the port you're hosting on. But if you get a 404, it means that there's something listening on that port, it just doesn't know where the page is or it's not mapped to a particular resource properly. Commented Apr 25, 2015 at 2:33
  • unrelated, success is obslete, .done is the way to go. please read the Deprecation Notice at api.jquery.com/jquery.ajax Commented Apr 25, 2015 at 4:15
  • oh ok thanks did not realize success had become obsolete Commented Apr 26, 2015 at 2:47

1 Answer 1

10

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}");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. Is routes.Ignore("{page}.aspx/{*webmethod}"); anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.