I am newbie to axios and I need to ask what is the different between using jQuery ajax and axios.
By jquery I often use like this:
d.init = function() {
var urload = 'http://fashionablebloggertemplate.blogspot.com/feeds/posts/default?alt=json-in-script';
$.when(
$.ajax({
type: 'POST',
url: urload,
context: this,
contentType: "application/json",
dataType: 'jsonp',
success: function(data) {
//dataget here
}
});
}
but in axios, I use like code below, it appears an error: No 'Access-Control-Allow-Origin' header is present on the requested resource
while it is working well with jQuery ajax for different domain and local.
state = {
dataposts: []
}
componentDidMount() {
axios.get(`http://fashionablebloggertemplate.blogspot.com/feeds/posts/default?alt=json-in-script`)
.then(res => {
const dataposts = res.data;
this.setState({ dataposts });
})
}
Can everyone explains for me and how to make it work?