我使用YII2 + /kartik-v/bootstrap-fileinput
插件。当用户将其拖放到上传输入中时,我需要上传文件。通过ajax请求进行。当我将“ showUpload
”选项设置为“ false
”并使用ajax动作设置“ uploadUrl
”时,更改文件事件没有服务器请求。
<?= $form->field($model, 'logotype')->widget(FileInput::class, [
'options' => [ 'accept' => 'image/*' ],
'pluginOptions' => [
'showCaption' => false,
'showRemove' => false,
'showUpload' => false,
'browseClass' => 'btn btn-primary btn-block',
'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ',
'uploadUrl'=> '/module/controller/action'
],
]); ?>
我希望表单在服务器上创建ajax POST
,并且当用户选择图像并且无需另外按“上载”按钮时,文件中的数据就会被保存。是否有可能使用此插件?还是我应该编写一个自定义处理程序onchange
事件?插件选项中可能会有某种回调。
答案 0 :(得分:0)
您可以使用change
事件在选择文件后手动触发上传,并触发ajax上传,您应该调用upload
方法。
请参见下面的代码
$('#input-id').on('change', function(event) {
$(this).fileinput('upload');
});
希望有帮助
答案 1 :(得分:0)
对我来说,“ filebatchselected”事件有效。
最初为https://plugins.krajee.com/file-input-ajax-demo/6
g++ -c -pipe --std=c++11 -O3 -fPIC -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_CORE_LIB -I. -I. -Iwtf -I../../../qtbase/include -I../../../qtbase/include/QtCore -I. -I../../../qtbase/mkspecs/linux-g++ -o StringQt.o wtf/qt/StringQt.cpp
wtf/qt/StringQt.cpp:36:1: error: prototype for ‘WTF::String::String(const QString&)’ does not match any in class ‘WTF::String’
String::String(const QString& qstr)
In file included from wtf/qt/StringQt.cpp:29:0:
./wtf/text/WTFString.h:480:5: error: candidates are: WTF::String::String(WTF::HashTableDeletedValueType)
String(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { }
^
./wtf/text/WTFString.h:146:5: error: WTF::String::String(WTF::String&&)
String(String&& other) : m_impl(other.m_impl.release()) { }
^
./wtf/text/WTFString.h:145:5: error: WTF::String::String(const WTF::String&)
String(const String& other) : m_impl(other.m_impl) { }
^
In file included from wtf/qt/StringQt.cpp:29:0:
./wtf/text/WTFString.h:140:5: error: template<unsigned int charactersCount> WTF::String::String(const char (&)[charactersCount], WTF::String::ConstructFromLiteralTag)
String(const char (&characters)[charactersCount], ConstructFromLiteralTag) : m_impl(StringImpl::createFromLiteral<charactersCo
^
./wtf/text/WTFString.h:134:27: error: WTF::String::String(WTF::ASCIILiteral)
WTF_EXPORT_STRING_API String(ASCIILiteral characters);
^
./wtf/text/WTFString.h:131:5: error: WTF::String::String(WTF::RefPtr<WTF::StringImpl>)
String(RefPtr<StringImpl> impl) : m_impl(impl) { }
^
./wtf/text/WTFString.h:130:5: error: WTF::String::String(WTF::PassRefPtr<WTF::StringImpl>)
String(PassRefPtr<StringImpl> impl) : m_impl(impl) { }
^
./wtf/text/WTFString.h:129:5: error: WTF::String::String(WTF::StringImpl*)
String(StringImpl* impl) : m_impl(impl) { }
^
./wtf/text/WTFString.h:126:27: error: WTF::String::String(const char*)
WTF_EXPORT_STRING_API String(const char* characters);
^
./wtf/text/WTFString.h:125:27: error: WTF::String::String(const LChar*)
WTF_EXPORT_STRING_API String(const LChar* characters);
^
./wtf/text/WTFString.h:122:27: error: WTF::String::String(const char*, unsigned int)
WTF_EXPORT_STRING_API String(const char* characters, unsigned length);
^
./wtf/text/WTFString.h:121:27: error: WTF::String::String(const LChar*, unsigned int)
WTF_EXPORT_STRING_API String(const LChar* characters, unsigned length);
^
./wtf/text/WTFString.h:118:27: error: WTF::String::String(const UChar*)
WTF_EXPORT_STRING_API String(const UChar*);
^
./wtf/text/WTFString.h:115:14: error: template<long unsigned int inlineCapacity, class OverflowHandler> WTF::String::String(const WTF::Vector<short unsigned int, inlineCapacity, OverflowHandler>&)
explicit String(const Vector<UChar, inlineCapacity, OverflowHandler>&);
^
./wtf/text/WTFString.h:104:27: error: WTF::String::String(const UChar*, unsigned int)
WTF_EXPORT_STRING_API String(const UChar* characters, unsigned length);
^
./wtf/text/WTFString.h:101:5: error: WTF::String::String()
String() { }
^
wtf/qt/StringQt.cpp:43:1: error: prototype for ‘WTF::String::String(const QStringRef&)’ does not match any in class ‘WTF::String’
String::String(const QStringRef& ref)
^
In file included from wtf/qt/StringQt.cpp:29:0:
./wtf/text/WTFString.h:480:5: error: candidates are: WTF::String::String(WTF::HashTableDeletedValueType)
String(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { }
^
./wtf/text/WTFString.h:146:5: error: WTF::String::String(WTF::String&&)
String(String&& other) : m_impl(other.m_impl.release()) { }
^
./wtf/text/WTFString.h:145:5: error: WTF::String::String(const WTF::String&)
String(const String& other) : m_impl(other.m_impl) { }
^
In file included from wtf/qt/StringQt.cpp:29:0:
./wtf/text/WTFString.h:140:5: error: template<unsigned int charactersCount> WTF::String::String(const char (&)[charactersCount], WTF::String::ConstructFromLiteralTag)
String(const char (&characters)[charactersCount], ConstructFromLiteralTag) : m_impl(StringImpl::createFromLiteral<charactersCo
^
./wtf/text/WTFString.h:134:27: error: WTF::String::String(WTF::ASCIILiteral)
WTF_EXPORT_STRING_API String(ASCIILiteral characters);
^
./wtf/text/WTFString.h:131:5: error: WTF::String::String(WTF::RefPtr<WTF::StringImpl>)
String(RefPtr<StringImpl> impl) : m_impl(impl) { }
^
./wtf/text/WTFString.h:130:5: error: WTF::String::String(WTF::PassRefPtr<WTF::StringImpl>)
String(PassRefPtr<StringImpl> impl) : m_impl(impl) { }
^
./wtf/text/WTFString.h:129:5: error: WTF::String::String(WTF::StringImpl*)
String(StringImpl* impl) : m_impl(impl) { }
^
./wtf/text/WTFString.h:126:27: error: WTF::String::String(const char*)
WTF_EXPORT_STRING_API String(const char* characters);
^
./wtf/text/WTFString.h:125:27: error: WTF::String::String(const LChar*)
WTF_EXPORT_STRING_API String(const LChar* characters);
^
./wtf/text/WTFString.h:122:27: error: WTF::String::String(const char*, unsigned int)
WTF_EXPORT_STRING_API String(const char* characters, unsigned length);
^
./wtf/text/WTFString.h:121:27: error: WTF::String::String(const LChar*, unsigned int)
WTF_EXPORT_STRING_API String(const LChar* characters, unsigned length);
^
./wtf/text/WTFString.h:118:27: error: WTF::String::String(const UChar*)
WTF_EXPORT_STRING_API String(const UChar*);
^
./wtf/text/WTFString.h:115:14: error: template<long unsigned int inlineCapacity, class OverflowHandler> WTF::String::String(const WTF::Vector<short unsigned int, inlineCapacity, OverflowHandler>&)
explicit String(const Vector<UChar, inlineCapacity, OverflowHandler>&);
^
./wtf/text/WTFString.h:104:27: error: WTF::String::String(const UChar*, unsigned int)
WTF_EXPORT_STRING_API String(const UChar* characters, unsigned length);
^
./wtf/text/WTFString.h:101:5: error: WTF::String::String()
String() { }
^
wtf/qt/StringQt.cpp:50:28: error: no ‘WTF::String::operator QString() const’ member function declared in class ‘WTF::String’
String::operator QString() const
^
Makefile.WTF:3895: recipe for target 'StringQt.o' failed