我试图了解Angular中工厂和服务的概念.我在控制器下面有以下代码
init();
function init(){
$http.post('/services', {
type : 'getSource',
ID : 'TP001'
}).
success(function(data, status) {
updateData(data);
}).
error(function(data, status) {
});
console.log(contentVariable);
};
function updateData(data){
console.log(data);
};
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常.但是当我将$ http服务转移到工厂时,我无法将数据返回给控制器.
studentApp.factory('studentSessionFactory', function($http){
var factory = {};
factory.getSessions = function(){
$http.post('/services', {
type : 'getSource',
ID : 'TP001'
}).
success(function(data, status) {
return data;
}).
error(function(data, status) {
});
};
return factory;
});
studentApp.controller('studentMenu',function($scope, studentSessionFactory){
$scope.variableName = [];
init();
function init(){
$scope.variableName = studentSessionFactory.getSessions();
console.log($scope.variableName);
};
});
Run Code Online (Sandbox Code Playgroud)
使用工厂是否有任何优势,因为$ http甚至可以在控制器下工作
所以我试图将图像与表单数据一起上传到服务器.我正在使用FileReader API将图像转换为数据并上传到服务器.我使用AJAX Jquery跟踪类似于HTML5上传器的代码.
数据在jquery中转换,但没有任何内容发送到服务器,也没有生成错误.
$('#formupload').on('submit', function(e){
e.preventDefault();
var hasError = false;
var file = document.getElementById('file').files[0];
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = shipOff;
function shipOff(event) {
result = new Image();
result.src = event.target.result;
var fileName = document.getElementById('file').files[0].name;
$.post('test.php', { data: result, name: fileName });
}
Run Code Online (Sandbox Code Playgroud)
PHP代码
<?php
$data = $_POST['data'];
$fileName = $_POST['name'];
echo $fileName;
$fp = fopen('/uploads/'.$fileName,'w'); //Prepends timestamp to prevent overwriting
fwrite($fp, $data);
fclose($fp);
$returnData = array( "serverFile" => $fileName );
echo json_encode($returnData); …Run Code Online (Sandbox Code Playgroud) 我正在创建一个带有express.js和angular,js的web应用程序,客户端通过facebook进行身份验证.对于facebook身份验证,我使用facebook-node-sdk连接facebook并检索详细信息.
通过url重定向进行身份验证时,代码运行良好.但是当我POST从客户端发送请求以调用相同的代码时,相同的代码不返回任何结果
服务器代码
app.post('/login', Facebook.loginRequired(), function(req, res){
var result = {};
req.facebook.api('/me', function(err, user) {
console.log(user);
if(user !== undefined){
result.status = 1;
result.name = user.name;
res.contentType('json');
res.write(JSON.stringify(result));
res.render('index')
res.end();
}
else{
result.status = 0;
result.name = "Error signing into Facebook";
res.contentType('json');
res.write(JSON.stringify(result));
res.render('/')
res.end();
}
});
});
Run Code Online (Sandbox Code Playgroud)
调用上面的代码时没有错误.console.log说明:
POST /登录302.
那么可以通过POST请求验证Facebook,还是应该始终是直接的URL请求?如果是这样的任何选项通过POST进行身份验证?
所以我目前将我的项目从jQuery移植到AngularJS,我在jQuery中有以下代码
jQuery代码
$(document).ready(function()
{
var icons = {
header: "ui-icon-circle-arrow-e",
activeHeader: "ui-icon-circle-arrow-s"
};
$( "#Session" ).accordion({
icons: icons
});
});
Run Code Online (Sandbox Code Playgroud)
我在AngularUI中找不到任何图标选项.是否有任何解决方法在AngularUI手风琴中添加标题图像?试图使用字体真棒的图标
<accordion-group heading="My Current Sessions" class="icon-book">
<div>Content Goes here</div>
</accordion-group>
Run Code Online (Sandbox Code Playgroud)
上面的代码在相邻的行上有图标和标题,而不是在同一行.
我在My Mountain Lion Server上将PHP从5.3.15升级到5.4.16.从此链接执行以下步骤
我还更新了bash配置文件的新PHP路径.现在我显示了两个不同的PHP版本.
在终端which php命令点升级php
/usr/local/php/bin/php/
php -v也指向升级版5.4.16.
但是页面创建phpinfo()并phpmyadmin仍然指向PHP/5.3.15
在Mountain Lion服务器上进行PHP升级后是否还需要重新配置其他文件?
我在运行Mac Mountain Lion的本地计算机上执行了相同的安装.我没有升级问题.