Reputation: 1778
I am trying to send html code to php page as POST data as follows:
report_data['finalhtml'] = '\n\n\n<!------ page split ----\>\n<div class="clearfix">'+html+'</div><!------ page split end ----\>\n\n\n';
var report = JSON.stringify(report_data);
var report_json = encodeURIComponent(window.btoa(report));
var url = baseurl+"/pdf-report";
var newForm = jQuery('<form>', {
'action': url,
'method': 'POST',
'target': '_top'
}).append(jQuery('<input>', {
'name': 'report_details',
'value': report_json,
'type': 'hidden',
}))
.append(jQuery('<input>', {
'name': 'project_name',
'value': successdata.ProjectTitle,
'type': 'hidden'
}));
$('body').append(newForm);
SAT_utilities_js.RemovePageLoader();
newForm.submit();
But when I am getting data on PHP page I am getting error as ERR_BLOCKED_BY_XSS_AUDITOR
I googled about this error and came to know that I need to BASE64 the html code. So I did base64 in JS but then I am not getting proper base64 decoded string in php. The reason is that my JS Object is converted into JSON first and then encoded in BASE64.
The issue is that I can not use base64 alone and I also can not use stringify alone.
Now I am not getting full proof way to send my html code to PHP page using jQuery FORM and POST method.
Please suggest any way to send HTML code from JS to PHP page
Upvotes: 2
Views: 85
Reputation: 171698
Your base64 and stringify process flow seems wrong.
You really only wanted the html strings base64 encoded before you stringify to json
Try
var finalhtml = '<...html string...>';
report_data['finalhtml'] = btoa(finalhtml);
var report = JSON.stringify(report_data);
Then in php
$report_detail = json_decode($_POST['report_detail']);
$base64_html = $report_detail->finalhtml;
Upvotes: 1