没有web服务器的Ajax代码 [英] Ajax Code without web server
问题描述
我在系统中运行没有服务器的ajax,我用这个
javascript函数创建了一个index.html: p>
函数do_the_click(url)
{
alert('this this do_the_click');
$ .ajax({
async:false,
url:url,
contentType:text / html,
类型:GET,
dataType:text / html,
success:function(data){
alert('data');
}});
}
以及我的HTML正文内容是:
< a href =Java Collections.htmlclass =buttonid =javacollectionsonclick =do_the_click('this.href');/ > Java集合< / a>
我可以在警告窗口*中获取此消息*此方法内do_the_click *,但无法在警报窗口中获取数据,因此无法在index.html中获取页面Java Collections.html,
我已经在Google上搜索了很多关于如何在没有使用jquery.ajax中的服务器的情况下在本地加载数据,但没有得到任何好的解决方案,所以我认为它对其他人以及如果它驻留在计算器上是有好处的。
我能够在没有web服务器的情况下运行ajax,问题出在我的代码上面,我在文件系统上运行的代码也可以使用。
函数do_the_click(brl)
{
alert('this this do_the_click');
alert(brl);
var request = $ .ajax({
async:false,
url:brl,
contentType:text / html,
类型:GET,
dataType:html,
});
request.done(函数(msg){
alert(msg);
$(#contentarea).load(msg,function(){
alert(Load was performed。);
});
});
$ b $ request.fail(function(jqXHR,textStatus){
alert(Request failed:+ textStatus);
});
$ b Java Collections
I am running ajax without a server on my system, I have created one index.html with this
javascript function:
function do_the_click(url)
{
alert('inside this method do_the_click');
$.ajax({
async: false,
url : url,
contentType: "text/html",
type : "GET",
dataType : "text/html",
success: function(data){
alert('data');
}});
}
and my HTML body content is :
<a href="Java Collections.html" class="button" id="javacollections" onclick="do_the_click('this.href');"/>Java Collections</a>
I m able to get the this message in alert window *inside this method do_the_click* but not able to get the data in alert window, and so not able to get the page Java Collections.html in the index.html,
I have searched very much on google that how to load the data locally without using server in jquery.ajax but doesn't get any good solution, so I think that its good for others as well if it reside on stackoverflow.
解决方案 I m able to run the ajax without webserver the problem was with my code the code written below that i had run on my filesystem u can use that as well.
function do_the_click(brl)
{
alert('inside this method do_the_click');
alert(brl);
var request = $.ajax({
async: false,
url: brl,
contentType: "text/html",
type : "GET",
dataType : "html",
});
request.done(function( msg ) {
alert(msg);
$( "#contentarea" ).load( msg, function() {
alert( "Load was performed." );
});
});
request.fail(function( jqXHR, textStatus ) {
alert( "Request failed: " + textStatus );
});
}
Java Collections
这篇关于没有web服务器的Ajax代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!