通过jQuery更改数据URL [英] Change data-url via jquery
问题描述
我正在尝试使用jquery来更改文件上传所使用的data-url
属性.但这似乎不起作用.文件上传采用旧值.
I am trying to use jquery to change the data-url
attribute used by a file upload. But it doesn't seems to be working. The file upload takes the old value.
$('#fileupload').attr('data-url', "https://api.mysite.com/optimizeonly");
HTML
<input id="fileupload" class="fileupload" type="file" name="file[]" data-url="https://api.mysite.com/upload" multiple="">`
摘要:
$('#fileupload').attr('data-url', "https://api.mysite.com/optimizeonly");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="fileupload" class="fileupload" type="file" name="file[]" data-url="https://api.mysite.com/upload" multiple="">
1
我正在使用jquery文件上传模块,尽管从标签中可以明显看出. 整个代码可从实时演示中获取(只需检查元素)
I am using jquery file upload module , i though this was evident from the tags. The whole code is available from the live demo (just inspect element)
推荐答案
输入的data-url
属性为插件 >初始化.此后不会自动读取.您是否尝试过如下更新URL?
The data-url
attribute of the input is read by the plugin when initializing. It is not automatically read afterwards. Have you tried updating the URL as follows?
var fu = $('#fileupload');
fu.fileupload('option', 'url', fu.data('url'));
当然,这将在使用
fu.data('url', 'new-url-you-want-here');
我认为您可以完全跳过更新属性,而仅更改插件的选项.
and you could, I think, skip updating the attribute altogether and only change the option of the plugin.
fu.fileupload('option', 'url', 'new-url-you-want-here');
这篇关于通过jQuery更改数据URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!