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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 SQL server表计算问题
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出