Search code examples
javascriptjqueryxmldrupal-8acquia

jQuery posting xml data getting trimmed while sending


I am posting xml data to server which is working fine in my local, but after uploaded to server, its breaking the data at client side I hope.

Request payload in my local server

<ApiRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <ApiKey>xxxxxxxxxxx</ApiKey>
  <Data xsi:type="Subscriber">
    <Mode>AddAndUpdate</Mode>
    <Force>true</Force>
    <ListId>16</ListId>
    <Email>[email protected]</Email>
    <Firstname>abc</Firstname>
    <Lastname>cdf</Lastname>
  </Data>
</ApiRequest>

enter image description here

Request payload after uploading to server

<ApiRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <ApiKey>xxxxxxxxxxx
  <Data xsi:type="Subscriber">
  <Mode>AddAndUpdate
  <Force>true
  <ListId>16
  <Email>[email protected]
  <Firstname>abc
  <Lastname>cdf

enter image description here

This is integration of ExpertSender. files are hosted in Acquia Cloud.

What could be the possibility of this issue? How can I solve this?

This is my Post call code,

var postData = '<ApiRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"><ApiKey>xxxxxxx</ApiKey><Data xsi:type="Subscriber"><Mode>AddAndUpdate</Mode><Force>true</Force><ListId>16</ListId><Email>'+emailVal+'</Email><Firstname>'+firstnameVal+'</Firstname><Lastname>'+lastnameVal+'</Lastname><Properties><Property><Id>1</Id><Value xsi:type="xs:integer">'+telVal+'</Value></Property></Properties></Data></ApiRequest>';
    var postUrl = 'https://api2.esv2.com/Api/Subscribers';
    jQuery.ajax({
        type: "POST",
        url: postUrl,
        data: postData,
        contentType: "text/plain; charset=utf-8",
        cache: false,
        success: function(response) {
            success.html(sucessMsg);
        },
        error: function(response) {
          var xmlData = jQuery.parseXML( response.responseText );
          var message = jQuery( xmlData ).find("Message").text();
          if (message.search("Email is invalid")){
            failed.html(errorMsg);
          }else{
            failed.html(message);
          }
        }
    });

Solution

  • It was the text editor configuration.

    In Drupal-8, the "mail text" text editor's "Correct faulty and chopped off HTML" option actually doing crazy with XML content.

    enter image description here