JSON响应返回整页HTML而不是JSON字符串

时间:2014-05-20 06:38:14

标签: jquery asp.net ajax

我正在使用AJAX来获取JSON格式的数据。我的代码是:

$.ajax({
    type: 'POST',
    dataType: 'json',
    contentType: "application/json; charset=utf-8",
    url: 'Dashboard.aspx/GetOfficesByDept',
    data: "{ 'Dept': '" + deptcode + "','SelectedDate':'" + dateselected + "'}",
    success:function(response) {
            // do stuff
    },
    error: function(request, status, error) {
            alert(request.responseText);
    }
});

vb代码是:

<System.Web.Services.WebMethod()> _
   Public Shared Function GetOfficesByDept(ByVal Dept As String, ByVal SelectedDate As String) As List(Of Data)

        Dim MyInterface As fwInterface.fwInterface.fwInterface
        Dim MyImplementer As New fwBLL.SelfUpdates
        Dim MyCommand As New SqlClient.SqlCommand
        Dim MyTable As New DataTable

        MyInterface = MyImplementer
        MyCommand.Parameters.Clear()


        Dim dataList As New List(Of Data)()

        MyCommand.Parameters.AddWithValue("@tableName", "GetOfficesByDeptAndEntryDate")
        MyCommand.Parameters.AddWithValue("@deptid", Dept)
        MyCommand.Parameters.AddWithValue("@EntryDate", UpToDate)

        Dim dtOffices As New DataTable()
        dtOffices = MyInterface.SelectAll(MyCommand)


        Dim colName As String = "Offices Count"
        Dim val As Integer = 0


        If dtOffices.Rows.Count > 0 Then
            val = dtOffices.Rows.Count
        End If
        dataList.Add(New Data(colName, val))
        Return dataList
    End Function

当我在fiddler上检查JSON响应时,它返回的是整页HTML而不是JSON Response。我的代码中有什么问题吗?

它在我的本地系统上工作正常(仅在Local上返回有效的JSON响应)但在实时服务器上没有。

由于

0 个答案:

没有答案