我的角度js代码无法使用imgur API上传图片。 angular js http post方法 angular js http post方法
HTML:
null
这是我的JS:
List<Point> pointList = new ArrayList<>();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 500);
JPanel panel = new JPanel(){
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
Point l = null;
for(Point p : pointList){
if(l != null && p != null)
g.drawLine(l.x, l.y, p.x, p.y);
l = p;
}
}
};
frame.setContentPane(panel);
panel.addMouseMotionListener(new MouseMotionListener() {
boolean isDrawing = false;
@Override
public void mouseDragged(MouseEvent e) {
pointList.add(e.getPoint());
isDrawing = true;
panel.repaint();
}
@Override
public void mouseMoved(MouseEvent e) {
if(isDrawing)
pointList.add(null); //null is a placeholder to mean line is finished
isDrawing = false;
}
});
frame.setVisible(true);
谢谢!
编辑:没有回调errorCallback和successCallback。
答案 0 :(得分:1)
我会改变你的代码:
if ($_POST['submit'])
{
$statu=mail($email_to,$email_subject,$email_message);
mail($email_to,$email_subject,$email_message);
if($statu==TRUE)
echo 'email has sent !';
else
echo 'email did not send !';
}
然后是html:
angular.module('stalkcalibrator', []) //best practise is not to declare a variable to contain this
.controller('adminController',['$scope','$log','$http', function($scope,$log,$http){ // safe dependency injection
var self = this; //self will contain the data from the controller. I dislike to put all into the scope.
//array of data for each stalk. PULL FROM JSON FILE!
self.stalks = [{id:1, name:2, thumbnail:3, note:4}, {id:9, name:10, thumbnail:11, note:12}, {id:5, name:6, thumbnail:7, note:8}];
//array of image uploads
self.img;
self.num = 1;
self.getStalks = function($scope){};
self.upload = function() {
$http({
headers: {'Authorization': 'Client-ID 010fe699c18e3c9'},
url: 'https://api.imgur.com/3/',
type: 'POST',
data: {'image': self.img}
}).then(function successCallback(response) {
self.num = 2;
$log.log('called and successful', response);
}, function errorCallback(err) {
self.num = 3;
$log.log('called but error', err);
});
};
}]);
试试这个,我认为问题可能在
<body ng-controller="adminController as ac">
<h1 id="title">Calibrator - Admin Upload</h1>
<!-- back to admin home -->
<div id="back"><a href="admin.html">Admin Home</a></div>
<!-- form used to upload one or more images -->
<form>
Upload image <input type="file" ng-model="ac.img" accept="image/*" id="file" />
<!-- executes js upload function with uploaded images -->
<button ng-click="ac.upload()">Submit</button>
<p ng-bind="ac.num"></p>
</form>
</body>
您点击了按钮而不是文本(这是能够调用上传功能的实际锚点)。
有了这个,我们至少应该能够在控制台中看到一些东西
答案 1 :(得分:1)
解决。事实证明,self.img是Imgur API的错误文件类型。必须转换为base64并进行@Gianmarco建议的编辑