<script type="text/javascript">
var Page={
//开发环境
host:"localhost:8080/webgame1/",
//运行环境
//host:"42.120.16.151:8080/webgame1/",
webHost:"http://"+Page.host,
chatHost:"ws://"+Page.host+"ChatServlet.do?channelId=",
type:"POST",
dataType:"json",
gameId:"",
//返回数据
returnData:"",
currentPage:"",
asyncProcess:function(_url,_data,_callback){
$.ajax({
type:this.type,
url:_url,
dataType:this.dataType,
data:_data,
success:_callback,
});
}
}
$(document).ready(function(){
alert(Page.webHost);
});
</script>
为什么打印出来的是undefined呢?这个问题导致我发异步请求的时候是错误的路径。
var Page={
//开发环境
host:"localhost:8080/webgame1/",
//运行环境
//host:"42.120.16.151:8080/webgame1/",
webHost:"http://"+Page.host,
chatHost:"ws://"+Page.host+"ChatServlet.do?channelId=",
type:"POST",
dataType:"json",
gameId:"",
//返回数据
returnData:"",
currentPage:"",
asyncProcess:function(_url,_data,_callback){
$.ajax({
type:this.type,
url:_url,
dataType:this.dataType,
data:_data,
success:_callback,
});
}
}
$(document).ready(function(){
alert(Page.webHost);
});
</script>
为什么打印出来的是undefined呢?这个问题导致我发异步请求的时候是错误的路径。
解决方案 »
- 如何在图片底部加提示,鼠标经过又不闪动?
- 有没有什么好的基于谷歌地图开发的点子呢
- 如何将被十六进制编码的汉字还原为可以正常浏览的汉字?
- 求助 getelement 问题
- 有一个项目问题,需要大家帮忙!
- 有人做过DIV层的浮动弹出窗口吗?请给我实例,好吗,谢谢
- htm如何传值到ASPX页面中
- 求代码,得到这种格式的日期时间,并且会跳动
- 如何取得表格的指定行
- 代码:<a href="" onclick="javascript:window.alert('asda')">Test</a>,这是一个hyperlink,我想点击它的时候只执行javascript,为不想它打开新页面,如何做到?
- JQuery中 属性选择器为什么有的有@有的没有呢?
- 关于javascript截取字符串的问题
//...
host: "localhost:8080/webgame1/", //webHost:"http://"+Page.host, /*TypeError: Page is undefined*/ webHost:"http://localhost:8080/webgame1/", // 硬编码或使用getWebHost方法
getWebHost: function(){return "http://" + this.host},
//...
}alert(Page.webHost)
alert(Page.getWebHost())
var Page = function()
{
this.host = ..;
this.data = ...;
this.webHost = this.host + 'http'.....
}var page = new Page();
host:function(){
var a="localhost:8080/webgame1/";
window.pagehost=a;
return a;
}(),
host: "localhost:8080/webgame1/", webHost:"http://"+this.host,
但是使用getWebHost()方法就能取啊?
webHost:function(){
return "http://"+this.host
}
再调用时,其内部this将指向Page
这是javascript的基础问题,crying_boy已经解答了,不过我建议你有时间的话,认真学习一下原生javascript。看下这个帖子,或许对你有所启示:http://topic.csdn.net/u/20120912/10/ad32ebff-5f34-4f75-8cb7-dd9597dc1661.html