Angularjs $ HTTP与方法JSONP发送数据没有工作服务 [英] Angularjs $http service with method JSONP sending data not working
本文介绍了Angularjs $ HTTP与方法JSONP发送数据没有工作服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Angularjs可以用$ HTTP服务与方法,我们发送数据JSONP
$ HTTP({
方法:'JSONP',
网址:HTTP://plv.localhost/register回调= JSON_CALLBACK',
数据:{名称:'一些名字'}
})。成功(功能(数据,状态,头,配置){
的console.log(成功);
})错误(功能(数据,状态,头,配置){
的console.log('错误');
});
解决方案
是的,你可以!请参见 NG。$ HTTP
一>。你的网址
缺少回调
参数:
$ HTTP({
方法:'JSONP',
网址:HTTP://plv.localhost/register回调= JSON_CALLBACK',
params:一个{名称:'一些名字'}
})。成功(功能(数据,状态,头,配置){
的console.log(成功);
})错误(功能(数据,状态,头,配置){
的console.log('错误');
});
In Angularjs Can we send data using $http service with method "JSONP"
$http({
method: 'JSONP',
url: 'http://plv.localhost/register?callback=JSON_CALLBACK',
data : { name : 'some name' }
}).success(function(data, status , header, config){
console.log('success');
}).error(function(data, status , header, config){
console.log('error');
});
解决方案
Yes, you can! See ng.$http
. Your url
is missing the callback
parameter:
$http({
method: 'jsonp',
url: 'http://plv.localhost/register?callback=JSON_CALLBACK',
params: { name: 'some name' }
}).success(function(data, status , header, config) {
console.log('success');
}).error(function(data, status , header, config) {
console.log('error');
});
这篇关于Angularjs $ HTTP与方法JSONP发送数据没有工作服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文