【发布时间】:2016-06-01 15:27:25
【问题描述】:
我正在使用 ionic 框架,尝试使用 http put 方法更新用户信息,但每次都会出错。我认为 php slim 框架代码没有问题,因为我从更改 this example put 方法代码中尝试了它,并给出了以下 put 代码和 slim 框架代码在那里工作。所以我认为 Angular js 代码有问题。 问题出在哪里?任何人都可以帮助我吗? 谢谢。
Slim 框架代码:
$app->put('/duzenle/:id',function($id) use ($app){
$request = $app->request();
$veri = json_decode($request->getBody());
$sql = "UPDATE sinav_users SET u_name=:u_name, u_realname=:u_realname, u_email=:u_email WHERE u_id=:u_id";
try {
$db = getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("u_name", $veri->u_name);
$stmt->bindParam("u_realname", $veri->u_realname);
$stmt->bindParam("u_email", $veri->u_email);
$stmt->bindParam("u_id", $id);
$stmt->execute();
$db = null;
echo json_encode($veri);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}})->name('duzenle');
Angularjs 代码:
$scope.duzenle=function(userr){
var url2="http://server_ip/sinav_api/duzenle/"+id;
console.log(url2);
var promise = $http({method: 'PUT', url: url2, data:userr, headers: {'Content-Type': 'application/x-www-form-urlencoded'}});
promise.success(function (data, status, headers, config, statusText) {
console.log("ok");
});
promise.error(function (data, status) {
console.log("fail");
});
};
范围内的用户数据:
<ion-view style="" title="Duzenle">
<ion-content class="has-header" overflow-scroll="true" padding="true">
<form style="" class="list" ng-repeat="user in userlist">
<label style="" class="item item-input">
<span class="input-label">Gercek isim<font color="red">*</font></span>
<input placeholder="Old:{{user.u_realname}}" ng-model="userr.u_realname" type="text" required>
</label>
<label style="" class="item item-input">
<span class="input-label">E-posta<font color="red">*</font></span>
<input placeholder="Old:{{user.u_email}}" ng-model="userr.u_email" type="email" required>
</label>
<label style="" class="item item-input">
<span class="input-label">Kullanıcı ismi<font color="red">*</font></span>
<input placeholder="Old:{{user.u_name}}" ng-model="userr.u_name" type="text" required>
</label>
<button style="" class="button button-positive button-block " ng-click="duzenle(userr)">Duzenle</button>
</form>
</ion-content>
【问题讨论】:
-
有任何可用的错误详情吗?
-
当尝试在控制台日志中获取错误状态时得到 0
-
如果可以的话,请添加控制台窗口的屏幕截图,包括来自服务器的响应。
-
数据空状态0 >link
-
服务器是否在同一个域中?如果不是 CORS 问题
标签: javascript php angularjs ionic-framework slim