C0deM0nkey C0deM0nkey -3 years ago 116
jQuery Question

Jquery, Ajax Error 404 with Webmethod url

I have done a lot of searching and everything I have found says that my setup should work (no one seems to have my exact issue and I dont seem to have other peoples issues).

I have done this before as an intern but i didnt set things up, now i am trying to do everything from scratch as close as I can to how I did it before and learning as I go. I am just trying to get a reply from my web method. Once I get it to work I can move on. Let me know what you guys think...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="Content/styles.css" rel="stylesheet" />
<!-- Bootstrap -->
<link href="Content/bootstrap.css" rel="stylesheet" />
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Calendar -->
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<div class="buttonsInline">
<button class="btn btn-info btn-lg" onclick='Test()' style="float:none">Alert</button>

function getVendorSystem() {
var system = sessionStorage.getItem('setSystem');
var vendor = sessionStorage.getItem('setVendor');

alert("System: " + system + "\nVendor: " + vendor);

function Test() {

method: 'post',
url: "WebNet.aspx/MSG",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: "true",
cache: "false",
success: function Succeed() {

error: function Error() {
alert("An Error Occured.")


Imports System.Web.Services
Imports System.Data.SqlClient

Public Class WebNet
Inherits System.Web.UI.Page

Public Shared Function MSG()
'Dim sqlConnection1 As New SqlConnection("Your Connection String")
'Dim cmd As New SqlCommand
'Dim reader As SqlDataReader

'cmd.CommandText = "SELECT * FROM Customers"
'cmd.CommandType = CommandType.Text
'cmd.Connection = sqlConnection1


'reader = cmd.ExecuteReader()
' Data is accessible through the DataReader object here.

Return 0

End Function

End Class


<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="WebNet.aspx.vb" Inherits="WebApplication1.WebNet" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

I am getting Error 404 with this. using Action for the url gives me Error 400.

Just typing into the URL http://localhost:63787/WebNet.aspx/MSG gives me 404, but http://localhost:63787/WebNet.aspx is fine, as it should.

Answer Source

As I thought, it wasnt the code that I wrote. I spent 3 days going over it i would certainly hop not.... but this did seem to fix it for now.

calling webmethod from jquery C# returning 404 error in .net aspx page

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download