2017-01-23 37 views
0

我嘗試通過查詢來加載來自其他網站的圖像和DIV更換使用jquery post從其他網站加載圖片?

MY HTML: 
<div id="img_30"></div> 
<div id="img_120"></div> 
<div id="img_day"></div> 
<div id="img_week"></div> 
<div id="img_month"></div> 

-

JQUERY: 

var symbol = $("#stock").val(); 
symbol = symbol.concat('*BK') 
$("#show_symbol").html(text_value); 

$("#img_30").html("<img src='dummy.png'>"); 
$("#img_120").html("<img src='dummy.png'>"); 
$("#img_day").html("<img src='dummy.png'>"); 
$("#img_week").html("<img src='dummy.png'>"); 
$("#img_month").html("<img src='dummy.png'>"); 

網站和參數(例如):

http://www.chartty.com/investorzChart.php?symbolnsources=symbol&period=Monthly&interval=1&Cycle=MONTH1 

所以我的jQuery .post()應該是這樣的:

$.post("http://www.chartty.com/investorzChart.php", 
{ symbolnsources: "symbolnsources", 
    period: "monthly", 
    interval:"1", 
    Cycle:"MONTH1", 
}) 
.done(function(data) { 
alert("Data Loaded: " + data); 
}); 

或不。

謝謝。

+0

您無法制作跨源JavaScript請求。你必須使JSONP調用... –

+0

http://stackoverflow.com/questions/17874730/how-to-make-cross-domain-request –

+1

可能的重複[如何使跨域請求](http:// stackoverflow.com/questions/17874730/how-to-make-cross-domain-request) –

回答

0

如果數據被附加到你需要一個GET請求的URL,也爲您的向上傳遞數據的末尾Cylcle後掉落額外逗號:

$.get("http://www.chartty.com/investorzChart.php", { 
    symbolnsources: "symbolnsources", 
    period: "monthly", 
    interval:"1", 
    Cycle:"MONTH1" 
}).done(function(data){ 
    //load the data into your site unfortunately the link provided is down so I can't see the data format returned 
}); 

這個答案是假設CORS啓用。