views:

255

answers:

3

I've written an ajax-enabled web page intended for use on my Wii. However, ajax doesn't appear to work on the Wii's Opera browser. This page works in IE, Chrome and FF, but not in Safari or Opera. Here is my jQuery test ajax call:

$.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"); }
});

Here is my test web service method:

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

There are no calls to DefaultWebService.asmx in my web server logs, so the browser isn't even trying to make the ajax request.
Are there any work-arounds available to get this working on the Wii? Thanks!

A: 

Not too familiar with ASP.. could it be that you need to JSON encode the return value? Or does "[WebMethod]" take care of that? Try this:

return "\"hello there\"";
Kip
[WebMethod] does take care of the JSON encoding of the return value.
Joel Harris
A: 

Have you tried changing the data being posted? This looks similar (though obviously not identical) to the issue posted here: http://stackoverflow.com/questions/291183/jquery-syntax-error-on-post-in-opera

TheJuice
I saw that post and I'm doubtful that it applies here. The problem in that case was that a javascript object was being created with an unquoted object key. I'm trying to pass an empty object with no keys.
Joel Harris
+1  A: 

Hi Joel, after a month I hope you've found the solution, but if you haven't I'd like to help out. I wrote a pretty basic test, just this:

<?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"&gt;&lt;/script&gt;
    <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>

but it does work just fine in the Opera versions I tried it in (including some early 9.x versions that might be aligned to the Wii one - I'm not sure what the closest desktop equivalent is though)

hallvors
(also tested in 8.54 FWIW)
hallvors