我如何在加载函数中使用url传递字符串变量?

时间:2021-03-29 21:03:27

here i have variable fileVal takes path of file like uploads/import/abc.pdf

这里我有变量fileVal采取文件的路径,如uploads / import / abc.pdf

var fileVal = $('#fileimport').val();

var fileVal = $('#fileimport')。val();

here fileVal takes path of file like uploads/import/abc.pdf

这里fileVal接受像uploads / import / abc.pdf这样的文件路径

i have to send this file path as url variable to a php file and then display result on messagediv. like

我必须将此文件路径作为url变量发送到php文件,然后在messagediv上显示结果。喜欢

  $('#messagediv').load('../xyz.php?file='+fileVal);

here without url variable, its working perfect getting values to the messagediv.

这里没有url变量,它的工作完美获取了messagediv的值。

But where as using url variable its not.

但是在哪里使用url变量不是。

How i can solve this?

我怎么能解决这个问题?

2 个解决方案

#1


1  

try with encodeURIComponent()

尝试使用encodeURIComponent()

var fileVal =  encodeURIComponent($('#fileimport').val());

#2


0  

That should work fine except you have a syntax error

这应该可以正常工作,除非你有语法错误

// $var fileVal = $('#fileimport').val();
var fileVal = $('#fileimport').val();

#1


1  

try with encodeURIComponent()

尝试使用encodeURIComponent()

var fileVal =  encodeURIComponent($('#fileimport').val());

#2


0  

That should work fine except you have a syntax error

这应该可以正常工作,除非你有语法错误

// $var fileVal = $('#fileimport').val();
var fileVal = $('#fileimport').val();