我生成使用時間戳這樣的URL:爲什麼我的字符串不能用作URL?
var writeDate = function(){
var x = new Date();
year = x.getFullYear();
month = (x.getMonth()+1) < 10 ? '0'+(x.getMonth()+1) : (x.getMonth()+1);
date = x.getDate() < 10 ? '0'+x.getDate() : x.getDate();
time = x.getHours() < 10 ? '0'+x.getHours() : x.getHours();
minute = x.getMinutes() < 10 ? '0'+x.getMinutes() : x.getMinutes();
var timeStamp = String(year+'-'+month+'-'+date+' '+time+':'+minute+':00.000');
return String("http://107.20.173.235/BlufinAPI/Service/WhackAScrip.svc/GetWASOneMinuteSensexDatawithPosition?TimeStamp="+timeStamp);
}
//使用函數
$.ajax({
cache: false,
type: "GET",
async: false,
url: writeDate(),//getting URL but not retrieving the live data
dataType: "jsonp",
success: function (msg) {
$(msg).each(function(i,value){
seArray[i]=value.CurrentPrice;
})
showResult();
},
error: function (xhr) {
console.log('update:'+msg);
}
然後調用,我使用返回的URL調用我的JSON功能,但它的檢索實時數據這是錯的嗎?
你試過看什麼writeDate()返回? console.info是你的朋友。 – Thilo 2012-03-13 06:25:27