JQuery 不会在 ASPX 中运行
Posted
技术标签:
【中文标题】JQuery 不会在 ASPX 中运行【英文标题】:JQuery Will Not Run In ASPX 【发布时间】:2019-05-19 11:16:05 【问题描述】:我正在尝试在 .aspx 页面中使用 Cloudinary JQuery SDK,使用以下代码:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js" type="text/javascript"></script>
<script src="https://cdn.rawgit.com/cloudinary/cloudinary_js/master/js/jquery.ui.widget.js" type="text/javascript"></script>
<script src="https://rawgit.com/cloudinary/cloudinary_js/master/js/jquery.iframe-transport.js" type="text/javascript"></script>
<script src="https://rawgit.com/cloudinary/cloudinary_js/master/js/jquery.fileupload.js" type="text/javascript"></script>
<script src="https://rawgit.com/cloudinary/cloudinary_js/master/js/jquery.cloudinary.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function()
console.log("Ready!");
$.cloudinary.config(
cloud_name: 'MYCLOUD'
)
$('.cloudinary_fileupload').unsigned_cloudinary_upload('MYUNSIGNEDUPLOADPRESET',
cloud_name: 'MYCLOUD',
tags: 'browser_uploads'
,
multiple: true
)
.bind('cloudinarydone', function(e, data)
// inspect data.result for return value with link to the uploaded image and more
console.log('Upload result', data.result);
// Create a thumbnail of the uploaded image, with 150px width
var image = $.cloudinary.image(
data.result.public_id,
secure: true,
width: 150,
crop: 'scale'
);
$('.gallery').prepend(image);
);
);
</script>
还有
<asp:Panel runat="server" ID="JQuery">
<input name="file" type="file" class="cloudinary-fileupload"/>
</asp:Panel>
很遗憾,当我选择一张图片时,什么也没有发生,上传也永远不会完成。
谁能指出导致 JQuery 脚本无法按预期工作的问题?
【问题讨论】:
你需要做一些基本的调试。当您查看浏览器的网络选项卡时,是否会加载所有脚本?您的 JavaScript 控制台中是否出现任何错误?控制台中是否记录了任何内容?这些是您需要在问题中提出的详细信息。 谢谢@mason。所有脚本都已加载,但有两个版本的 JQuery。 JavaScript 控制台中没有错误。我的代码中的“就绪”消息是唯一记录到控制台的内容。选择图像后,网络选项卡中没有任何反应,尽管从那里应该可以看到上传。 【参考方案1】:问题是我在 html 中使用了错误的类名。
以下内容:
<asp:Panel runat="server" ID="JQuery">
<input name="file" type="file" class="cloudinary-fileupload"/>
</asp:Panel>
应改为:
<asp:Panel runat="server" ID="JQuery">
<input name="file" type="file" class="cloudinary_fileupload"/>
</asp:Panel>
【讨论】:
以上是关于JQuery 不会在 ASPX 中运行的主要内容,如果未能解决你的问题,请参考以下文章
jQuery .get in aspx(不使用单独的 HTML)