duanlianyun0462 2011-07-31 06: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-31 07: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条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分