[英]jQuery .Load and iis7
I am trying some AJAX calls for the first time. 我第一次尝试一些AJAX呼叫。 My site is hosted on my own IIS7, (http:// myUserName :8078/HomePage.aspx). 我的网站托管在我自己的IIS7上(http:// myUserName :8078 / HomePage.aspx)。
Here is the jScript. 这是jScript。
<script type="text/javascript" src="jQuery1.4.2.js"/>
<script type="text/javascript">
$(document).ready(LoadText);
function LoadText() {
$("#Content1").load("data.txt");
}
"content1" is a content place holder. “ content1”是内容占位符。 My IIS is set to .net 4 too. 我的IIS也设置为.net 4。
My problem is that the data.txt contents is never loaded. 我的问题是data.txt的内容从不加载。 It is in the same directory as the page. 它与页面在同一目录中。 I haven't got much experience in IIS so I am wondering if I am missing a setting or something. 我在IIS方面没有太多经验,所以我想知道我是否缺少设置或其他东西。
Thanks 谢谢
You can't use a single-tag XHTML-style script tag for JavaScript. 您不能对JavaScript使用单标签XHTML样式的脚本标签。 Change your first line to: 将您的第一行更改为:
<script type="text/javascript" src="jQuery1.4.2.js"></script>
For some reason, the script tag can't be shortened down to just a single tag, you have to have separate opening and closing tags. 由于某种原因,不能将script标签缩短为一个标签,您必须具有单独的开始和结束标签。
Is data.txt in the root folder of your site? data.txt是否在您网站的根文件夹中? If so, the .load() method takes a URL so try "/data.txt" 如果是这样,.load()方法将使用URL,因此请尝试“ /data.txt”
I recommend you pass the ClientID
and file path
into the function as arguments, but the code below should work: 我建议您将ClientID
和file path
作为参数传递给函数,但是下面的代码应该可以工作:
<script type="text/javascript" src='<%= Page.ResolveUrl("~/jQuery1.4.2.js")%>'></script>
<script type="text/javascript">
$(document).ready(function() {
LoadText();
});
function LoadText() {
$("#<%= Content1.ClientID %>").load('<%= Page.ResolveUrl("~/data.txt")%>');
}
</script>
LoadText() is a function. LoadText()是一个函数。 Try: 尝试:
$(document).ready(
LoadText();
);
Also I would suggest using lower camel case for function names. 我也建议对函数名称使用小写的驼峰形式。 Upper camel case functions as in LoadText() suggests by convention that it is a contructor. 像LoadText()一样,大写驼峰函数按惯例暗示它是构造函数。
$(document).ready(
loadText();
);
You can also log something in the loadText() function to verify that it actually gets executed. 您还可以在loadText()函数中记录某些内容,以验证它是否真正被执行。
function loadText() {
$("#Content1").load("data.txt");
console.log('tried to load data.txt');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.