title: Why is WP7 WebBrowser InvokeScript call throwing Error: 80020101?
body: <p>This error seems to throw for anything that goes wrong in the javascript function that is called:</p>
  
  <pre><code>SystemException was unhandled    
  An unknown error has occurred. Error: 80020101.
  </code></pre>
  
  <p>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:</p>
  
  <p>In Silverlight:</p>
  
  <pre><code>MyBrowser.InvokeScript("getData", "/Me/Feed?numberOfResults=-1", "MyFeed");
  </code></pre>
  
  <p>The Javascript loaded into the WebBrowser</p>
  
  <pre><code>function getData(url, context) {
      $.ajax({
          url: url,
          dataType: 'jsonp',
          success: function (result) {
              callback(result, context);
          }
      });
  }
  </code></pre>
  
  <p>But later I want to post data back to the server, and I am doing the same thing:</p>
  
  <pre><code>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);
          }
      });
  }
  </code></pre>
  
  <p>Now I get the exception.</p>
  
  <p>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.</p>
  
  <pre><code>postData("sampledata", "PostTest");
  </code></pre>
  
  <p>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).</p>
  
  <p>I also tried calling it on a separate thread, using Dispatcher.BeginInvoke for good measure and no dice.</p>
  
  <pre><code>Dispatcher.BeginInvoke(() =&gt;
  {
      MyBrowser.InvokeScript("postData", "thedata", "CreatePost");
  });
  </code></pre>
  
  <p>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.</p>
  
  <p>Can anyone tell me what I am doing wrong, or what it is I don't understand about using InvokeScript and Ajax together??</p>
  
  <p>Thanks!</p>
  
  <p>[EDIT - adding this inline (was in the comments) because I'm getting the question a lot]</p>
  
  <p>I have worked on this for 6 hours and this is what I'm seeing:</p>
  
  <ul>
  <li>there are 2 different events from which I am making these calls; 1) when the page load has completed on the browser control, 2) when a user taps my "post" button</li>
  <li>the error does NOT occur when the Ajax call is a GET from the load event</li>
  <li>the error DOES occur when calling the same GET call from the user event</li>
  <li>the error ALSO DOES OCCUR when calling the Ajax call using POST from the load event</li>
  <li>the error does NOT occur when calling a function that does not attempt any Ajax from the user event</li>
  </ul>