使用http post将raw-html编码为数据发送

时间:2014-02-27 14:04:41

标签: javascript encoding utf-8 base64

我正在尝试使用HTTP-post发送JSON字符串。当我尝试将raw-html数据作为文本添加到JSON字符串时,我收到服务器错误500。

这是我的代码:

 var data0 = $("#nameInput").val();
 var data1 = generateJSON();
 var data2 = $("#wellContainer").html();
 var jsondataobject = { name: data0, counter: counter, json: data1, html: escape(data2) };
 var stringobject = JSON.stringify(jsondataobject);

  $.ajax({
  type: 'POST',
  dataType: 'text',
  url: "http://localhost:49162/Admin/SaveNewTemplate",
  data: "jsonData=" + stringobject,
  contentType: "application/x-www-form-urlencoded; charset=utf-8",
     success: function (returnPayload) {
      console && console.log("request succeeded");
     },
     error: function (xhr, ajaxOptions, thrownError) {
     console && console.log("request failed");
      },

       processData: false,
       async: false
        });
         document.location.reload();
          //loadTemplate(data0);

         }

当我用$("#wellContainer").html()将jtml-data添加到json-object时,我得到500错误。我尝试了不同的html内容,但我得到了同样的错误。

如果我使用btoa()将其编码为base64,则http-post有效,但btoa()不支持字符。

我该怎么编码呢?我需要åäö字符。

0 个答案:

没有答案