duanlianyun0462 2011-07-30 22:07
浏览 116
已采纳

如何通过AJAX在URL中发送变量?

I'm sending the variable like this:

xmlhttp.open("GET","insert-karma.php?pid=<? echo $pid; ?>",true);

The AJAX part doesn't seem to be the problem, if I check the Sript the PHP is echoing the integer correctly. (It displays the url as: insert-karma.php?pid=5). However the PHP isn't getting the variable. (I tried echoing and it does't show anthing)

This is the PHP file:

// Connect to db;

$pid = $_POST['pid'];

$sql="UPDATE Poems SET Karma = Karma + 1 WHERE Pid = '$pid'";

// Disconnect form database;

What am I doing wrong? How do I manage to send $pid to the PHP update-karma.php?

  • 写回答

4条回答 默认 最新

  • douhuigang9550 2011-07-30 23:06
    关注

    first you should not use PHP in you ajax requests it's just make things more complicated and PHP is for server side scripting in the first place secound , you should use xmlhttp.open("POST","insert-karma....) if u plain to use POST Third the only important difference (not the only but the important) between POST and Get is :

    GET requests can be cached

    GET requests can remain in the browser history

    GET requests can be bookmarked

    GET requests can be distributed & shared

    GET requests can be hacked lool

    so u cant use Get For unsecured and dangerous action like LOGIN OR ...

    POST Can handel too long Data

    Post is more secured Cuz it's not gonna be cached or saved in history or bookmarked

    u can clearly notice that POST's dont display in the browsers address bar but Get do 'www.anything.com/index.php?bla=bhe'

    i hope that i am helping here !! :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥35 西门子博图v16安装密钥提示CryptAcquireContext MS_DEF_PROV Error of containger opening
  • ¥15 mes系统扫码追溯功能
  • ¥40 selenium访问信用中国
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
  • ¥30 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥50 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥15 alpha101因子里哪些适合crypto?