代码之家  ›  专栏  ›  技术社区  ›  Joel Harris

Opera、Wii、Ajax、Jquery和asp.net

  •  1
  • Joel Harris  · 技术社区  · 15 年前

    我已经写了一个支持ajax的网页,打算在我的Wii上使用。然而,ajax在Wii的Opera浏览器上似乎不起作用。此页面可在IE、Chrome和FF中使用,但不能在Safari或Opera中使用。 以下是我的jQuery测试ajax调用:

    $.ajax({
        type: "POST",
        url: "DefaultWebService.asmx/Hello",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) { alert(msg.d); },
        error: function() { alert("error in DefaultWebService.asmx/Hello"); }
    });
    

    以下是我的测试web服务方法:

    [WebMethod]
    public string Hello()
    {
        return "hello there";
    }
    

    在我的web服务器日志中没有对DefaultWebService.asmx的调用,因此浏览器甚至没有尝试发出ajax请求。
    谢谢

    3 回复  |  直到 15 年前
        1
  •  2
  •   hallvors    15 年前

    <?php
        if( $_SERVER['REQUEST_METHOD']=='POST' ){
            echo file_get_contents('php://input');
            exit;
        }
    ?>
        <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js"></script>
        <script type="text/javascript">
        $.ajax({
        type: "POST",
        url: location.href,
        data: '{"test":"passed" }',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) { alert(msg.test); },
        error: function() { alert("error while testing"); }
    });
        </script>
    

    但在我试用过的Opera版本中,它确实工作得很好(包括一些可能与Wii版本一致的早期9.x版本,不过我不确定最接近的桌面版本是什么)

        2
  •  0
  •   Kip    15 年前

    不太熟悉ASP。。是否需要对返回值进行JSON编码?或者说 [WebMethod]

    return "\"hello there\"";
    
        3
  •  0
  •   Community CDub    7 年前

    您是否尝试过更改正在发布的数据?这看起来与此处发布的问题类似(尽管明显不同): jQuery syntax error on POST in Opera