0

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...

producs.html

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Product</title>
<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>
</head>

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

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

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


function Test() {

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

            alert("SUCCESS!");
        },
        error: function Error() {
            alert("An Error Occured.")
        }
    });
}
</script>

WebNet.aspx.vb

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

Public Class WebNet
    Inherits System.Web.UI.Page

    <WebMethod()>
    Public Shared Function MSG()
        MsgBox("Updated")
        '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

        'sqlConnection1.Open()

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

        'sqlConnection1.Close()
        Return 0

    End Function

End Class

WebNet.aspx

<%@ 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>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>

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.

1
  • 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. stackoverflow.com/questions/29860304/… Commented Aug 9, 2017 at 12:59

2 Answers 2

0

Try typing the full path to your aspx containing WebMethod, or try moving the whole script to the aspx containing webmethod.

Another thing you can try as adding as String to your function (Public Shared Function MSG() as String)

Regards

Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

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.