JavaScript 跨域訪問(API接口)實現原理分析

首先看看源代碼以下:json

<script>
var jsonpfej4g9k4zv111;
function _jsonpfej4g9k4zv111(data){ 
    jsonpfej4g9k4zv111 = data; 
}
</script> 
<script src="http://localhost/api.ashx?type=defalut&callback=_jsonpfej4g9k4zv111"></script> 
<script>
	console.log(jsonpfej4g9k4zv111);
</script>複製代碼



接下來, 看Vue.jsonp跨域, 同理:api

<script> 
var vm = new Vue({ 
el: '#app' 	
,data: {
		message: 'Hello World'
	}
	,mounted() { 
console.log('mounted'); 
this.$http.jsonp('http://localhost:59486/api.ashx?type=defalut')
.then(function(result){ 
console.log('jsonp data', result.body); 		
}); 
}
}); 
</script>複製代碼


接下來,你怎麼看...
跨域

相關文章
相關標籤/搜索