function rate(rating, comment, contentType) {
  // Encode the rating and the comment so they are URL safe
  rating = encodeVal(rating);
  comment = encodeVal(comment);
  // Prepare the payload as the specified content type
  let payload = '';
  switch (contentType) {
    case 'text/xml':
      payload = `
        <?xml version="1.0" encoding="UTF-8"?>
        <vote>
          <rating>${rating}</rating>
          <comment>${comment}</comment>
        </vote>
      `;
      break;
    case 'application/json':
      payload = JSON.stringify({ rating: rating, comment: comment });
      break;
    case 'text/x-yaml':
      let payloadYaml = new YAML();
      payload = payloadYaml.dump([{'rating': rating, 'comment': comment}]);
      break;
    case 'base64':
      // b -> a (b to a) converts from string to base64
      payload = btoa(`rating=${rating},comment=${comment}`);
      break;
    case 'text/plain':
      payload = `rating=${rating},comment=${comment.replaceAll(',', '%2C')}`;
      break;
    default:
      // The default is the same as x-www-form-urlencoded here
      payload = `rating=${rating}&comment=${comment}`;
      break;
  }
  // Send the request to the server and display the response
  sendRequest(payload, contentType);
}
/**
 * Encodes the given rating submission content, and then submits the
 * information to the server. Once that has been submitted, displays the
 * response.
 * @param {string} rating The user's rating, a value from 1-5
 * @param {string} comment The user's comment, a block of text
 * @param {string} contentType The content-type to send the data as
 */
Encodes the given rating submission content, and then submits the
information to the server. Once that has been submitted, displays the
response.
@param {string} rating The user's rating, a value from 1-5
@param {string} comment The user's comment, a block of text
@param {string} contentType The content-type to send the data as
Encodes the given rating submission content and then submits the information to the server . Once that has been submitted displays the response . @param { string } rating The user ' s rating a value from 1 - 5 @param { string } comment The user ' s comment a block of text @param { string } contentType The content - type to send the data as
function rate(rating, comment, contentType) {
  rating = encodeVal(rating);
  comment = encodeVal(comment);
  let payload = '';
  switch (contentType) {
    case 'text/xml':
      payload = `
        <?xml version="1.0" encoding="UTF-8"?>
        <vote>
          <rating>${rating}</rating>
          <comment>${comment}</comment>
        </vote>
      `;
      break;
    case 'application/json':
      payload = JSON.stringify({ rating: rating, comment: comment });
      break;
    case 'text/x-yaml':
      let payloadYaml = new YAML();
      payload = payloadYaml.dump([{'rating': rating, 'comment': comment}]);
      break;
    case 'base64':
      payload = btoa(`rating=${rating},comment=${comment}`);
      break;
    case 'text/plain':
      payload = `rating=${rating},comment=${comment.replaceAll(',', '%2C')}`;
      break;
    default:
      payload = `rating=${rating}&comment=${comment}`;
      break;
  }
  sendRequest(payload, contentType);
}
function rate ( rating , comment , contentType ) { rating = encodeVal ( rating ) ; comment = encodeVal ( comment ) ; let payload = '' ; switch ( contentType ) { case 'text/xml' : payload = ` ${ rating } ${ comment } ` ; break ; case 'application/json' : payload = JSON . stringify ( { rating : rating , comment : comment } ) ; break ; case 'text/x-yaml' : let payloadYaml = new YAML ( ) ; payload = payloadYaml . dump ( [ { 'rating' : rating , 'comment' : comment } ] ) ; break ; case 'base64' : payload = btoa ( ` ${ rating } ${ comment } ` ) ; break ; case 'text/plain' : payload = ` ${ rating } ${ comment . replaceAll ( ',' , '%2C' ) } ` ; break ; default : payload = ` ${ rating } ${ comment } ` ; break ; } sendRequest ( payload , contentType ) ; }
Encodes the given rating submission content, and then submits the
 information to the server.
Encodes the given rating submission content and then submits the information to the server .
// Encode the rating and the comment so they are URL safe // Prepare the payload as the specified content type // b -> a (b to a) converts from string to base64 // The default is the same as x-www-form-urlencoded here // Send the request to the server and display the response