NormB
NormB

Reputation: 41

"+" sign conversion happening

"+" sign in path gets converted to space

The code snippet below works just fine until my file path contains a "+" symbol, whereupon, when it reaches Download.php it has been converted into a space

    $('#ViewPdf').on('click', function() {
        var file = $('#PdfPath').val();
        if(file) {
            $(location).prop('href', 'Download.php?DeleteTarget&download_file='+file);
        }
        else { alert('No pdf file so cannot view'); }
    });

I am unsure whether the problem is a JavaScript one or php. Some sort of escaping or character conversion looks to be necessary but I am unsure what.

Upvotes: 1

Views: 66

Answers (2)

R3tep
R3tep

Reputation: 12864

You can use encodeURIComponent at the initialisation of your variable file.

Like that you encode the + sign as %2B

var file = encodeURIComponent($('#PdfPath').val());

Upvotes: 2

Hasta Dhana
Hasta Dhana

Reputation: 4719

Try using encodeURIComponent() :

var file = encodeURIComponent($('#PdfPath').val());

Upvotes: 3

Related Questions