0

我已經做了很多的搜索和一切我已經找到了說,我的設置,就可以(似乎沒有人有我確切的問題,我好像還沒有其他人的問題)。jQuery的阿賈克斯錯誤404 WEBMETHOD網址

我以前做過這樣的實習生,但我沒有設置好了,現在我試圖做的一切從頭開始接近我能如何,我以前做過和學習,我去。我只是試圖從我的web方法得到答覆。一旦我開始工作,我可以繼續前進。讓我知道你們想...

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> 

我得到錯誤404與此。使用URL操作給了我錯誤400
只需鍵入到URL http://localhost:63787/WebNet.aspx/MSG給了我404,但http://localhost:63787/WebNet.aspx是好的,因爲它應該。

+0

因爲我認爲,它不是我寫的代碼。我花了3天時間去了解它,我肯定跳不到......但是現在看起來似乎修復了它。 https://stackoverflow.com/questions/29860304/calling-webmethod-from-jquery-c-sharp-returning-404-error-in-net-aspx-page – C0deM0nkey

回答

0

嘗試輸入包含WebMethod的aspx的完整路徑,或嘗試將整個腳本移至包含webmethod的aspx。

另一件事你可以嘗試如添加的字符串給你的函數(公共共享功能MSG()作爲字符串)

問候