首先,我正在使用离子框架开发移动应用程序
在一个工厂中,我需要与不在我的域中的服务器端进行通信(跨域请求)
我使用了这段代码,但它对我永远都行不通
$http.get({
url: 'http://test.wilson34.com/test.php',
data: {
"name": "peter"
}
}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
console.log('Success' + data);
alert(data)
}).
error(function(data, status, headers, config) {
console.log('Status : ' + status);
});
但是当使用jQuery时,它的作用就像魅力
jQuery.ajax({
url: 'http://test.wilson34.com/test.php',
data: {
"name": "peter"
}
}).
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
console.log('Success' + data);
alert(data)
}).
error(function(data, status, headers, config) {
console.log('Status : ' + status);
});
请帮助我在我的项目中不使用jQuery,任何建议t在angularJs中使用$ http来完成
提前致谢
$http.get('http://test.wilson34.com/test.php', {params: {name: 'peter'}
}).success(function(data, status, headers, config) {
console.log('Success' + data);
}).error(function(data, status, headers, config) {
console.log('Status : ' + status);
});
参数是具有键,值对的对象。在这种情况下,其计算结果为?name = peter
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句