制作Ajax Post请求 - > vb 7.1

时间:2015-05-13 13:08:04

标签: asp.net ajax vb.net visual-studio-2010 server

我看过很多在线帮助,但没有任何工作。这是我第一次使用vb.net

我有一个名为

的文件
AddRecord.aspx

在同一个文件夹中,我有一个名为

的文件
AddRecord.aspx.vb

在AddRecord.aspx中我有

$(document).ready(function () {
       $.ajax({
           type: "POST",
           contentType: "application/json; charset=utf-8",
           url: "AddRecord.aspx/getCurrentTime",
           data: '{something:"hello"}',
           dataType: "json",
           success: function (result) {
                alert("success");
           },
           error: function (result) {
                alert("Error");
           }
       });
});

在AddRecord.aspx.vb中我有这个

Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Web
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Net.Mail
Imports System.DirectoryServices
Imports System.Web.Security

Imports Web.SmartNav

    <WebMethod()> _
    Public Shared Sub getCurrentTime(ByVal name As String)

        Return

    End Sub

运行AddRecord一直给我警告错误而不是成功警报,所以我做错了什么?如何判断我的函数是否被调用(这是我第一次使用visual basic和visual studio)?

1 个答案:

答案 0 :(得分:0)

看起来您在客户端Web窗体的代码隐藏中定义了WebApi。 Web窗体使用回发模型来运行通过事件处理程序链接到客户端控件的服务器端代码,在这种情况下我认为这是不必要的。我不知道Postback模型会干扰WebApi,但我会避免它让调试这个问题变得更容易。

我不确定你想要对你的web服务做什么,因为你发布的方法是通过命名约定似乎是用于GET。从教程开始可能对您有所帮助。 Microsoft在此页面上提供了一个,但它位于C#:

http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api