答案 0 :(得分:0)
你可以用AJAX做到这一点。
如果您必须向https://api.rajaongkir.com/starter/province
发送GET,则AJAX请求将如下所示:
$.ajax({
url: "https://api.rajaongkir.com/starter/province",
type: "GET",
beforeSend: function(xhr){xhr.setRequestHeader('key', 'API Key');},
success: function() { //do something here post the GET }
});
更新:
您需要$.ajax
使用<head>
。您可以通过在项目中包含jQuery库来实现。在<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
中,添加以下内容:
@JsonIgnoreProperties(ignoreUnknown = true)
public class Artists {
private String ArtistName;
private String Stage;
private String Day;
private String Hour;
public Artists(){
}
public String getArtistName() {
return ArtistName;
}
public void setArtistName(String artistName) {
ArtistName = artistName;
}
public String getStage() {
return Stage;
}
public void setStage(String stage) {
Stage = stage;
}
public String getDay() {
return Day;
}
public void setDay(String day) {
Day = day;
}
public String getHour() {
return Hour;
}
public void setHour(String hour) {
Hour = hour;
}
@Override
public String toString() {
return "Artists [ArtistName=" + ArtistName + ", Stage=" + Stage + ", Day=" + Day + ", Hour=" + Hour + "]";
}
}
这应该使您能够使用AJAX发送异步网络请求。
我写了一个请求,我将GET发送到jQuery并在div中显示名称