如何通过AJAX传递当前用户ID? [英] How can I pass current user ID through AJAX?

查看:378
本文介绍了如何通过AJAX传递当前用户ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


有人可以帮助解决以下问题 - 我正在尝试传递用户ID中登录的当前会话用户,



只是插入0进入数据库。



见下面的代码:



我尝试过:



$ .ajax({

方法:'POST',

url:'DBInsert .php',

数据:{ID:ID},

成功:函数(数据){

$('。fav') .html(数据)

}

});

});

});





insert.php



Hi Can someone help with the below - I am trying to pass the current session user that is logged in User ID,

its just inserting 0 into the database.

See below code:

What I have tried:

$.ajax({
method: 'POST',
url: 'DBInsert.php',
data: {ID:ID},
success: function(data) {
$('.fav').html(data)
}
});
});
});


insert.php

<?php
//insert.php

推荐答案

.ajax({

方法:'POST' ,

url:'DBInsert.php',

数据:{ID:ID},

成功:函数(数据){
.ajax({
method: 'POST',
url: 'DBInsert.php',
data: {ID:ID},
success: function(data) {


('。fav')。html(数据)

}

});

});

});





insert.php



('.fav').html(data)
}
});
});
});


insert.php

<?php
//insert.php


由于JavaScript在客户端运行,因此您需要将用户ID存储在html中。一个简单的方法是使用隐藏字段然后使用你的php将会话中的用户ID写入隐藏字段,然后JavaScript从隐藏字段中提取它。
Since JavaScript runs on the client side you will need to store the user id in the html. An easy way to do it is to use a hidden field and then you use your php to write the user id from the session into the hidden field and then JavaScript pulls it from the hidden field.


这篇关于如何通过AJAX传递当前用户ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆