Skip to content Skip to sidebar Skip to footer

Jquery Load(function) For A Microsoft Word Document

This is for a school project the course is online and not very accurate anymore. I want to use the .load(function) combined with a .click function so when I click the corresponding

Solution 1:

From the jQuery documentation: https://api.jquery.com/load/

Description: Load data from the server and place the returned HTML into the matched element.

This isn't going to work for you because you're using a .docx file type which is not going to return html (or even regular text). It might manage to do something but the output is likely to be garbled. Do you have this massage.docx file on the server?

The following won't work at all:

$('.selection').load(massage.docx)

I think what you meant is (note that you must use a string here):

$('.selection').load("massage.docx")

But this still won't work because you are trying to load a microsoft word document as HTML, and that just simply won't function properly. You should convert your massage.docx either to regular text, or to an html file - upload it to the server in the same location that you are calling this javascript from, and try this again.

Also, use your browser's javascript console to check for JS errors. In chrome you can do this by right clicking anywhere, selecting "inspect element", and switching to the "Console" tab on the inspector tool.

EDIT:

If you want to make sure the click is even working at all, you might want to add some checks:

$(document).ready(function() {
    var massage=('massage.docx');
    $('.selection').click(function() {
        alert("Clicked!  Attempting to load...");
        $(this).load(massage, function(){
            alert("Loading finished!");
        });
    });
});

Solution 2:

try with txt document first:

<scripttype="text/javascript">
$(document).ready(function() {

    $('.selection').click(function() {
        $('.selection').load('test.txt');

    });
});
</script>

Post a Comment for "Jquery Load(function) For A Microsoft Word Document"