【问题标题】:Ajax/json call to asmx web service completes sucessfully but cant display resulting data对 asmx Web 服务的 Ajax/json 调用成功完成,但无法显示结果数据
【发布时间】:2013-10-10 14:45:45
【问题描述】:

我确定我没有正确格式化结果或类似的东西。任何帮助表示赞赏。谢谢,加里

这是 JavaScript 部分:

   $.ajax({
        type: 'POST',
        url: '../ajaxservices.asmx/HelloWorld',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        data: '{}',
         success: function(data){

           that.resultsField.innerHTML = data.d; 

        },
        error: function() {

            that.resultsField.innerHTML = 'Error'; 
        }
    });

这是网络服务部分:

namespace WorkbenchWebServices
{
    [System.Web.Script.Services.ScriptService()]
    [WebService(Namespace = "http://microsoft.com/webservices/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class ajaxservices : System.Web.Services.WebService
    {
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]

        public string HelloWorld(string name)
        {

            return "Gary Hello World-";
        }

【问题讨论】:

  • 我不知道“那个”是什么。设置 html 时设置为 .html(data)。我认为你的语法可能是错误的
  • 在你的成功函数中放置一个javascript警报,看看是否有什么东西回来了。 alert(JSON.stringify(data, null, '\t'));

标签: javascript ajax json asp.net-mvc-4 asmx


【解决方案1】:

正如马特所说,“那个”不存在...... 尝试使用:

$("#result").html(data);
//instead of using
//that.resultsField.innerHTML = data.d; 

<div id="result"></div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-27
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多