Ibid Athoillah Ibid Athoillah - 2 months ago 6
Ajax Question

how to post text '&nsbp ' using javascript?

The content that i want to send

<div id="preview">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</div>


Element function:

function _(obj) {
return document.getElementById(obj);
}


Ajax:

$.ajax({
type: 'POST',
url: 'http://<?php echo $domain ?>/libraries/ajax/pdf.php',
data: 'html=' + _("preview").innerHTML + '&nama=a',
dataType: 'html',
beforeSend: function() {},
success: function(response) {
Materialize.toast((response), 4000);
}
});


How to send
&nsbp
as text instead of
POST
parameter?

Answer

Use the encodeURIComponent(<string to be encoded>) to encode the data