最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why is WP7 WebBrowser InvokeScript call throwing Error: 80020101? - Stack Overflow

programmeradmin3浏览0评论

This error seems to throw for anything that goes wrong in the javascript function that is called:

SystemException was unhandled    
An unknown error has occurred. Error: 80020101.

I am using the javascript as an interface to a web-app backend, and I have two calls that are working fine, loading and returning JSON from an ajax call, that look like this:

In Silverlight:

MyBrowser.InvokeScript("getData", "/Me/Feed?numberOfResults=-1", "MyFeed");

The Javascript loaded into the WebBrowser

function getData(url, context) {
    $.ajax({
        url: url,
        dataType: 'jsonp',
        success: function (result) {
            callback(result, context);
        }
    });
}

But later I want to post data back to the server, and I am doing the same thing:

MyBrowser.InvokeScript("postData", "thedata", "CreatePost");

function postData(payload, context) {
    $.ajax({
        type: "POST",
        url: "/Post/Create?" + tz(),
        data: payload,
        dataType:"json",
        success:function (result) {
            callback(result, context);
        }
    });
}

Now I get the exception.

What is really strange is that I can immediately call the function from within the script and it posts to the back-end just fine.

postData("sampledata", "PostTest");

At first it seemed the only difference was that one was a GET and the other a POST, so I copied the GET ajax call into the second call (which happens on user input, where the first one happened on load). The result was the same (I get the same error). I can get other mands to fire in the javascript from this event as long as they don't contain ajax calls (it appears). So you might think that it is a timing thing - so I moved the call up above where I call the other InvokeScripts which are working, and it still doesn't work (same exception).

I also tried calling it on a separate thread, using Dispatcher.BeginInvoke for good measure and no dice.

Dispatcher.BeginInvoke(() =>
{
    MyBrowser.InvokeScript("postData", "thedata", "CreatePost");
});

I'm pletely baffled. There does seem to be some consistency, in that if a call fails it will fail every time, but I can't tell what is the difference between the calls that work and the ones that fail.

Can anyone tell me what I am doing wrong, or what it is I don't understand about using InvokeScript and Ajax together??

Thanks!

[EDIT - adding this inline (was in the ments) because I'm getting the question a lot]

I have worked on this for 6 hours and this is what I'm seeing:

  • there are 2 different events from which I am making these calls; 1) when the page load has pleted on the browser control, 2) when a user taps my "post" button
  • the error does NOT occur when the Ajax call is a GET from the load event
  • the error DOES occur when calling the same GET call from the user event
  • the error ALSO DOES OCCUR when calling the Ajax call using POST from the load event
  • the error does NOT occur when calling a function that does not attempt any Ajax from the user event

This error seems to throw for anything that goes wrong in the javascript function that is called:

SystemException was unhandled    
An unknown error has occurred. Error: 80020101.

I am using the javascript as an interface to a web-app backend, and I have two calls that are working fine, loading and returning JSON from an ajax call, that look like this:

In Silverlight:

MyBrowser.InvokeScript("getData", "/Me/Feed?numberOfResults=-1", "MyFeed");

The Javascript loaded into the WebBrowser

function getData(url, context) {
    $.ajax({
        url: url,
        dataType: 'jsonp',
        success: function (result) {
            callback(result, context);
        }
    });
}

But later I want to post data back to the server, and I am doing the same thing:

MyBrowser.InvokeScript("postData", "thedata", "CreatePost");

function postData(payload, context) {
    $.ajax({
        type: "POST",
        url: "/Post/Create?" + tz(),
        data: payload,
        dataType:"json",
        success:function (result) {
            callback(result, context);
        }
    });
}

Now I get the exception.

What is really strange is that I can immediately call the function from within the script and it posts to the back-end just fine.

postData("sampledata", "PostTest");

At first it seemed the only difference was that one was a GET and the other a POST, so I copied the GET ajax call into the second call (which happens on user input, where the first one happened on load). The result was the same (I get the same error). I can get other mands to fire in the javascript from this event as long as they don't contain ajax calls (it appears). So you might think that it is a timing thing - so I moved the call up above where I call the other InvokeScripts which are working, and it still doesn't work (same exception).

I also tried calling it on a separate thread, using Dispatcher.BeginInvoke for good measure and no dice.

Dispatcher.BeginInvoke(() =>
{
    MyBrowser.InvokeScript("postData", "thedata", "CreatePost");
});

I'm pletely baffled. There does seem to be some consistency, in that if a call fails it will fail every time, but I can't tell what is the difference between the calls that work and the ones that fail.

Can anyone tell me what I am doing wrong, or what it is I don't understand about using InvokeScript and Ajax together??

Thanks!

[EDIT - adding this inline (was in the ments) because I'm getting the question a lot]

I have worked on this for 6 hours and this is what I'm seeing:

  • there are 2 different events from which I am making these calls; 1) when the page load has pleted on the browser control, 2) when a user taps my "post" button
  • the error does NOT occur when the Ajax call is a GET from the load event
  • the error DOES occur when calling the same GET call from the user event
  • the error ALSO DOES OCCUR when calling the Ajax call using POST from the load event
  • the error does NOT occur when calling a function that does not attempt any Ajax from the user event
Share Improve this question edited Mar 25, 2011 at 17:30 Subcreation asked Mar 25, 2011 at 3:58 SubcreationSubcreation 1,35312 silver badges29 bronze badges 4
  • Does it do this with a natural XMLHTTPRequest? – mattsven Commented Mar 25, 2011 at 4:02
  • Is the page fully loaded when you call InvokeScript? Might be that the $.ajax function is not loaded yet? – Eugenio Pace Commented Mar 25, 2011 at 4:45
  • Hi, NeXXeuS - I'm not sure I understand what you are suggesting. Do you mean I should try to scrap using Javascript as an interface to the web app and access it directly? Mainly, my team didn't want to rewrite all their stuff just for this one client, and the other thing is that this approach provides the existing Facebook auth and avoids all cross-domain Silverlight issues – Subcreation Commented Mar 25, 2011 at 12:13
  • Eugenio, it is definitely loaded. I call getData when it loads and everything works fine. It is later on, when the user taps a button in my app, that the postData is called and gets this error. – Subcreation Commented Mar 25, 2011 at 12:15
Add a ment  | 

4 Answers 4

Reset to default 6

You'll get the 80020101 error if the javascript method can't be found or th JS throws an error.

In terms of finding the method, the control will match the signature exactly. This is not the standard javascript behaviour so be careful with this.

Beware of caching of the page (and it's contents) within the browser control as this catches a lot of people out. :(

Seeing the GET working with JSONP, and the POST not working at all, seems to imply that you may be going cross-domain? Typically on the same domain there is no need to use JSON*P*.

So my guess is that it is a violation of the same-origin policy.

I just fixed a similar problem.

It’s kind of strange… it requires: 1. Passing the parameters to the javascript function as one ma delimited string 2. Parsing the string in the javascript using split() 3. Creating a string of the expression (i.e. function call with the parameters) 4. Performing an eval() on the string expression.

I guess you could also pass a string that evals into a javascript array.

Tom

The only issue (as I have faced the same) due to the fact that your web browser control is not loaded and javascript function is being called.

As in one of the answers, it has been indicated.

发布评论

评论列表(0)

  1. 暂无评论