【发布时间】:2018-04-30 19:34:56
【问题描述】:
我有一个表单(以模态形式出现),您可以在其中上传图像裁剪并调整其大小。有两个按钮 Cancel 和 Save & Crop。当点击保存和裁剪时,我在functions.js 中有以下 jQuery:
/* handle functionality when click crop button */
jQuery('#save_crop').on('click', function(e){
e.preventDefault();
params = {
targetUrl: 'change_pic.php?action=save',
action: 'save',
x_axis: jQuery('#hdn-x1-axis').val(),
y_axis: jQuery('#hdn-y1-axis').val(),
x2_axis: jQuery('#hdn-x2-axis').val(),
y2_axis: jQuery('#hdn-y2-axis').val(),
thumb_width: jQuery('#hdn-thumb-width').val(),
thumb_height:jQuery('#hdn-thumb-height').val()
};
saveCropImage(params);
});
/* Function to save crop images */
function saveCropImage(params) {
jQuery.ajax({
url: params['targetUrl'],
cache: false,
dataType: "html",
data: {
action: params['action'],
id: jQuery('#hdn-profile-id').val(),
t: 'ajax',
w1: params['thumb_width'],
x1: params['x_axis'],
h1: params['thumb_height'],
y1: params['y_axis'],
x2: params['x2_axis'],
y2: params['y2_axis'],
image_name: jQuery('#image_name').val()
},
type: 'Post',
success: function (response) {
jQuery('#change_pic_modal').modal('hide');
jQuery(".imgareaselect-border1,.imgareaselect-border2,.imgareaselect-border3,.imgareaselect-border4,.imgareaselect-border2,.imgareaselect-outer").css('display', 'none');
jQuery("#profile_picture").attr('src', response);
jQuery("#preview-profile-pic").html('');
jQuery("#profile-pic").val();
},
error: function (xhr, ajaxOptions, thrownError) {
alert('status Code:' + xhr.status + 'Error Message :' + thrownError);
}
});
}
});
在change_pic.php我有以下内容:
首先是一个switch语句:
/* Get post details */
$post = isset($_POST) ? $_POST: array();
switch($post['action']) {
case 'save' :
saveProfilePic();
saveProfilePicTmp();
break;
default:
changeProfilePic();
}
有了以上内容,我现在有了case 'save':,这将激活saveProfilePic() 和saveProfilePicTmp()。后者工作正常,图像以经过清理的名称保存到正确的文件夹中。另一个saveProfilePic() 什么都不做,我不明白为什么?这是函数:
/* Function to handle save profile pic */
function saveProfilePic(){
include_once("config/config.php");
$post = isset($_POST) ? $_POST: array();
//Handle profile picture update with MySQL update Query using $options array
if($post['username-id']){
$sql_query = "SELECT * FROM users WHERE username = '".mysqli_escape_string($con, $post['username-id'])."'";
$resultset = mysqli_query($con, $sql_query) or die("database error:". mysqli_error($con));
if(mysqli_num_rows($resultset)) {
$sql_update = "UPDATE users set profile_pic='".mysqli_escape_string($con,$post['image_name'])."' WHERE username = '".mysqli_escape_string($con, $post['username-id'])."'";
mysqli_query($con, $sql_update) or die("database error:". mysqli_error($con));
}
}
}
($post['username-id']) 作为隐藏值来自表单,我需要将其与特定用户联系起来。谁能明白为什么这行不通?基本上我的表单上发生的事情是模态保持打开状态并且裁剪的图像区域消失了。模式应该关闭,但保持打开状态我假设 b/c saveProfilePic(); 没有执行。
任何帮助将不胜感激。
【问题讨论】: