Hi,
Currently, I faced a problem on loading json string into ejDiagram.
This is what I try to achieve:
1. Users can drag and drop palette items into ejDiagram
2. They can save the diagram. The diagram will convert to json string and save in database
3. When user refresh the page, the page will get the json string from database and load into ejDiagram.
Steps to trigger error:
1. when click on save button, the saveDiagram() will be called. This function will convert ejDiagram to json string and pass as parameter to C# for save in database.
2. when reload page, the loadState() will be called in order to load diagram state. However, ejDiagram unable to load anything. When I debug, I found this error : Uncaught SyntaxError: Unexpected token f.
In aspx:
function saveDiagram() {
saveData = $('#DiagramContent').ejDiagram('instance').save();
var diagramState = JSON.stringify(saveData);
var params = "{'state':'" + diagramState + "'}";
$.ajax({
type: "POST",
url: "Test.aspx/SaveDiagramState",
data: params,
contentType: "application/json;charset=utf-8",
dataType: "json",
success: onSaveSucess,
error: onError
});
}
var diagramState = '<%=diagramState %>';
function loadState(diagramState) {
if (diagramState)
{
$('#DiagramContent').ejDiagram('instance').load(JSON.parse(diagramState));
}
}
<div>
<ej:Diagram ID="DiagramContent" runat="server" Height="100%" Width="100%"></ej:Diagram>
</div>
After investigating the issue, I suspect the json string that I saved was wrong. Please assist me on how to solve this issue.
Thanks