The problem is that I can not pass a temporary path to the file in order to convert it into markdown text in the script again later.

Ajax request code:

$('#md').on('click', function(event){ event.preventDefault(); $.ajax({ type: 'POST', url: '<?=$dir?>/ajax/ajax_editor_md.php', data: {file: '<?=$_SERVER["DOCUMENT_ROOT"]."/upload/pdfFiles/670.docx"?>'}, success: function(result){ $('#area').html(result); alert('ready'); document.location.href = "<?=$_SERVER["SCRIPT_URI"]?>"; } }) }); 

Php handler code:

 $converter = new Docx2md\Docx2md; $converter = $converter->parseFile($_REQUEST["file"]); $markdown = $converter->markdown; echo $markdown; 

How can this problem be solved?

  • What errors does it give? - madfan41k
  • And what do you want something? Even if we assume that AJAX working, then: AJAX is executed, it sends a file, you accept the file, make a MARKDOWN, give it away and update the page where everything is empty (because the file is empty). ?) - Manitikyl
  • @Manitikyl, I get the text in the markdown format, pass it to success and fill in the text field into which this text is to be imported - Tigran Arustamov
  • @ madfan41k, {success: false} when you press the button - Tigran Arustamov
  • @ TigranArustamov what kind of url in the source? - Manitikyl

1 answer 1

Not really the answer, but try, firstly, change the file to 'file' , and secondly:

 success: function(result){ $('#area').html(result); alert('ready'); document.location.href = "<?=$_SERVER["SCRIPT_URI"]?>"; } 

replaced by:

 error:function(num) { alert(num); }, status:function (number) { alert(number); }, endstatus:function (number) { alert(number); }, success: function(data){ alert(data); } 

So you get all the information that you can get from AJAX , write us what you saw and so it will be easier for us to figure out what your problem is.

  • Now when I click it returns {"success": true, "url": "\ / kb \ / \ /"} - Tigran Arustamov
  • @TigranArustamov I probably understood what your error was, and where is the 670.docx file 670.docx ? If site.ru/upload/pdfFiles/... then replace '<?=$_SERVER["DOCUMENT_ROOT"]."/upload/pdfFiles/670.docx"?>' '/upload/pdfFiles/670.docx' . It should work like this: data: {'file': '/upload/pdfFiles/670.docx'}, - Manitikyl
  • returns the same {"success": true, "url": "\ / kb \ / \ /"}. I think this is my problem with url-addresses, because in the url address after updating the page this way: site.ru/kb//40 - Tigran Arustamov