nitdoc: Set all data type to JSON in Ajax queries
authorStefan Lage <lagestfan@gmail.com>
Mon, 27 May 2013 02:51:21 +0000 (22:51 -0400)
committerStefan Lage <lagestfan@gmail.com>
Tue, 28 May 2013 22:11:23 +0000 (18:11 -0400)
Change data type to JSON because there was somes troubles in commit
process

Signed-off-by: Stefan Lage <lagestfan@gmail.com>

share/nitdoc/scripts/js-facilities.js

index eb2c89c..9170a4d 100644 (file)
@@ -1008,6 +1008,7 @@ function setNewTree()
         type: "POST",\r
         url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/trees", \r
         async: false,\r
+        dataType:'json',\r
         data:'{ "base_tree" : "'+shaBaseTree+'", '+\r
                 '"tree":[{ '+\r
                     '"path":"'+ pathFile +'",'+\r
@@ -1018,7 +1019,7 @@ function setNewTree()
             '}',        \r
         success: function(success)\r
         { // si l'appel a bien fonctionné\r
-            shaNewTree = JSON.parse(success).sha;\r
+            shaNewTree = success.sha;\r
             setNewCommit();            \r
         },\r
         error: function(){\r
@@ -1034,13 +1035,14 @@ function setNewCommit()
         type: "POST",\r
         url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/commits", \r
         async: false,\r
+        dataType:'json',\r
         data:'{ "message" : "'+ commitMessage +'", '+\r
                 '"parents" :"'+shaLastCommit+'",'+ \r
                 '"tree": "'+shaNewTree+'"'+\r
              '}',        \r
         success: function(success)\r
         {\r
-            shaNewCommit = JSON.parse(success).sha;\r
+            shaNewCommit = success.sha;\r
             commit();          \r
         },\r
         error: function(){\r
@@ -1056,11 +1058,12 @@ function commit()
         beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", userB64); },\r
         type: "POST",\r
         url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/refs/heads/"+branchName, \r
+        dataType:'json',\r
         data:'{ "sha" : "'+shaNewCommit+'", '+\r
                 '"force" :"true"'+\r
              '}',\r
         success: function(success) { displayMessage('Commit created successfully', 40, 40); },\r
-        error:function(error){ displayMessage('Error ' + JSON.parse(error).object.message, 40, 40); }\r
+        error:function(error){ displayMessage('Error ' + error.object.message, 40, 40); }\r
     });\r
 }\r
 \r
@@ -1072,12 +1075,13 @@ function setBlob()
         type: "POST",         \r
         url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/git/blobs",         \r
         async: false,\r
+        dataType:'json',\r
         data:'{ "content" : "'+text.replace(/\r?\n/g, '\\n').replace(/\t/g, '\\t').replace(/\"/g,'\\"')+'", '+\r
                 '"encoding" :"utf-8"'+\r
             '}',\r
         success: function(success)\r
         {            \r
-            shaBlob = JSON.parse(success).sha;\r
+            shaBlob = success.sha;\r
             setNewTree();                  \r
         },\r
         error:function(error){ \r