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 commands 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 completely 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 comments) because I'm getting the question a lot]
I have worked on this for 6 hours and this is what I'm seeing:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With