2011-11-17 88 views
0

我在vb.net中返回JSON值时出现问题。请参阅下面的代码供您参考。在vb.net中使用JSON时出现对象对象错误

这是我的javascript代码。

//beging ajax  
$.ajax({  
    type: "POST",  
    url: "../webservices/addpage.asmx/getValue", 
    contentType: "application/json; charset=utf-8", 
    dataType: "json",  
    success: function(msg){ 
     alert(msg); 
    }, 
    error: function(msg){ 
     alert("Error "+ msg); 
    } 
}); 

    //end ajax 

这是我的JSON代码当我点击提交按钮:

<%@ WebService Language="VB" Class="addpage" %> 

Imports System 
imports System.Collections.Generic 
Imports System.Web 
Imports System.Web.Services 
Imports System.Web.Services.Protocols 
Imports System.Web.Script.Services 
Imports System.Web.Script.Serialization 
Imports System.Web.Hosting 
Imports System.Web.HttpContext 
Imports System.IO 

<WebService(Namespace:="http://tempuri.org/")> _ 
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ 
<ScriptService()> _ 
Public Class addpage 
    Inherits System.Web.Services.WebService 

    <WebMethod()> _ 
    Public Function getValue() As String 
     Return "Invalid" 
    End Function 

End Class 

我的情况是,当我按下按钮,那么它应该警惕由getValue函数,但返回的值我它总是提醒[Object Object]的错误。

我是vb.net的新手,请告诉我如何解决这个问题。

回答

0

根据此jquery documentation,$ .ajax查询的结果是一个jQuery XMLHttpRequest(jqXHR)对象,它是XMLHttpRequest的超集。

这意味着你应该能够改写你的成功方法:

success: function(msg){ 
    alert(msg.responseText); 
}, 
+0

嗨competent_tech,感谢您的答复,但是当我跟着你的建议“警告(msg.responseText)”现在说的“未定义”。请帮助我这个,提前谢谢你 – user760260