doulian8554 2013-12-02 07:25
浏览 51
已采纳

获取发布数据并在wordpress中创建会话变量

hi I am new to wordpress. I have few problems fromlong while. What I am trying to do is.. I have put some normal javascript code to send post data using AJAX..which is fine I have tested them out side wordpress but what I have to do is getting data in wordpress and storing themin wordpress session..a part of javascript code like

function purchase(img, price){
xmlHttp=CreateXmlHttpObject()
  if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  } 
  var url="http://www.example.com/purchase.php";
  xmlHttp.onreadystatechange=setTimeout(function(){stateChanged();}, 300)  ;
  xmlHttp.open("POST",url,true);
  xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  xmlHttp.send("image="+img+"&price="+price);
}

so please help me..how I get this data in wordpress and most important how do I store them in wordpress session. does normal $_POST works in wordpress????

  • 写回答

1条回答 默认 最新

  • douxian3828 2013-12-02 08:03
    关注

    Yes, $_POST[] works in wordpress. To set session add session_start() at the beginnning of file ie after <?php line. Then set session variable by - $_SESSION['variable_name'] = "variable value"; ex: $_SESSION['my_num'] = 5;

    Here session variable my_num is set to 5. To access this variable use

    echo $_SESSION['my_num'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?