我正在开发像twitter这样的关注/取消关注系统。我在过去的两个晚上尝试了几件事,但我无法弄清楚为什么元素的ID没有通过JQUERY传递给PHP。
请帮我纠正我的代码:
HTML:
<a class="btn btn-sm btn-default follow_user" id="<?php echo $row['user_id'];?>" title="Follow"><i class="glyphicon glyphicon-plus"></i> Follow</a>
JQUERY:
$(document).ready(function(){
$(document).on('click', '.follow_user', function(){
if($(this).attr('title') == 'Follow'){
$that = $(this);
var ID=$that.attr('id');
var action="follow";
$.post('include/common/follow_user.php?user_id='+ID+'&action='+action,function(){
$that.html('<i class="glyphicon glyphicon-check"></i> Following');
$that.attr('title','Unfollow');
$that.removeClass('btn btn-sm btn-default');
$that.addClass('btn btn-sm btn-success');
});
}
PHP代码:
<?php session_start(); ob_start();?>
<?php $user_id=$_SESSION['user_id'];?>
<!-- Follow OR Unfollow User
=============================================== -->
<?php
include "../db.php";
echo $follow_user=strip_tags(stripslashes(trim(mysqli_real_escape_string($con, $_POST['user_id']))));
echo $followee=$user_id;
echo $action=strip_tags(stripslashes(trim(mysqli_real_escape_string($con, $_POST['action']))));
if ($action=='follow'){
//follow
$sql="insert into follow(follower_id,following_id,follow_date)values('$followee','$follow_user',UTC_TIMESTAMP())";
if($con,$sql){}else{echo '<script type="text/javascript">toastr.error("We encountered a problem in doing that operation. Please try again after sometime.");</script>';}
}else{}
?>
答案 0 :(得分:0)
IEnumerator downloadImage()
{
string url = "http://wallpaper-gallery.net/images/hq-images-wallpapers/hq-images-wallpapers-12.jpg";
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
DownloadHandler handle = www.downloadHandler;
//Send Request and wait
yield return www.SendWebRequest();
if (www.isHttpError || www.isNetworkError)
{
UnityEngine.Debug.Log("Error while Receiving: " + www.error);
}
else
{
UnityEngine.Debug.Log("Success");
//Load Image
Texture2D texture2d = DownloadHandlerTexture.GetContent(www);
Sprite sprite = null;
sprite = Sprite.Create(texture2d, new Rect(0, 0, texture2d.width, texture2d.height), Vector2.zero);
if (sprite != null)
{
imageToUpdate.sprite = sprite;
}
}
}
应该像这样发送给post方法
Data
问题是您在url中将传递数据作为get方法。但是在尝试从post方法获取的服务器上。使用get方法。
$.post('include/common/follow_user.php',
{user_id:ID,action:action},
function(data,status){ alert(data);
});