1

I have an IE9 Web browser control embedded in a larger WPF application. I'm attempting to call InvokeScript and pass it a JSON string as a parameter:

webBrowser.InvokeScript("redrawPlot", new object[] { reDrawData });

The function redrawPlot uses the jquery method parseJSON to parse this back into an object:

redrawPlot = function(dataObj) {
        dataObj = $.parseJSON(dataObj);
        ...
}

When this runs in the WPF app I get the JavaScript error:

Invalid character

The contents of reDrawData (inspected in script debugger and in the WPF app) are:

"{\"plot0\":[{\"data\":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],\"label\":\"A-TOP-6\"}],\"plot1\":[{\"data\":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],\"label\":\"A-TOP-6\"}],\"plot2\":[{\"data\":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],\"label\":\"A-TOP-6\"}],\"plot3\":[{\"data\":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],\"label\":\"A-TOP-6\"}],\"plot4\":[{\"data\":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],\"label\":\"A-TOP-6\"}]}"

When I run this in under IE9 developer tools passing that string directly I get no errors.

Am I not calling InvokeScript correctly?

Mark
  • 106,305
  • 20
  • 172
  • 230
  • Does the string start with `"` or is that just how the debugger prints it? – Musa Nov 12 '12 at 02:27
  • @Musa, are you saying that I would need to add opening/closing `"` to my string to get it passed as a string to the javascript function? – Mark Nov 12 '12 at 02:38
  • No I wasn't, but from your question it seems they aren't. Try replacing all `\"` with just `"`. – Musa Nov 12 '12 at 02:40
  • @Musa, thanks so much. You were correct, I had over escaped the string. If you'd like to re-post your comment as an answer, I'll gladly accept it. – Mark Nov 12 '12 at 03:31

1 Answers1

1

The quotes around you properties and strings are escaped, they should not be. That is

{\"plot0\":[{\"data\":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],\"label\":\"A-TOP-6\"}],\"plot1\":[{\"data\":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],\"label\":\"A-TOP-6\"}],\"plot2\":[{\"data\":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],\"label\":\"A-TOP-6\"}],\"plot3\":[{\"data\":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],\"label\":\"A-TOP-6\"}],\"plot4\":[{\"data\":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],\"label\":\"A-TOP-6\"}]}

should be

{"plot0":[{"data":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],"label":"A-TOP-6"}],"plot1":[{"data":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],"label":"A-TOP-6"}],"plot2":[{"data":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],"label":"A-TOP-6"}],"plot3":[{"data":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],"label":"A-TOP-6"}],"plot4":[{"data":[[1,1111.11111111111],[2,1111.11111111111],[3,1111.11111111111]],"label":"A-TOP-6"}]}

Musa
  • 96,336
  • 17
  • 118
  • 137