Change data-url via jquery

你离开我真会死。 提交于 2019-12-13 23:12:56

问题


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="">`

Snippet:

$('#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="">

Edit : 1

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)


回答1:


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'));

Of course, this would be done after updating the data-url attribute of the element using

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');



回答2:


Can read the data-url property and revise it

    var fu = $('#mainplayer');
    fu[0].dataset.url = "Hello";
    console.log(fu[0].dataset.url);


来源:https://stackoverflow.com/questions/43043018/change-data-url-via-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!