doushen2154 2012-12-19 18:55
浏览 42

JSON发送问题

Hey guys so I am trying to have a JSON send over a value to another page in wordpress to create a session once a image is clicked on.

Here is the JSON code:

$('.item-post a').click(function() {
        var prodname = $('#hiddenpostitle');

           $.post('/overviewcheck-515adfzx8522', 
            { 
                'ProdName': prodname.val()

            },
            function(response) {

            },
            'json'
        );
    });

The #hiddenposttitle is the following: <?php echo "<input type='hidden' value='$title' id='hiddenpostitle' name='hiddenpostitle'/> "?>

So this sends to the overviewcheck page, which then has a template that has the follow:

<?php
/*
Template Name: overviewbackcheck
*/
session_start();

$prodname= $_POST['ProdName'];

$_SESSION['overviewprod'] = $prodname;

?>

Someone mentioned something about wordpress destroying sessions from calling session_start() but that's not the issue because I fixed that awhile ago, and have other sessions being made that work. It has to do something with the JSOn sending over and I am not to sure.

From here the overview page is opened with the following:

$(function()
    {
        $('.item-post a').colorbox({opacity:0.3, href:"../overviewa512454dzdtfa"});
    });

This is the colorbox code that will open the file the within the file I have:

<?php echo $_SESSION['overviewprod']; ?>

to echo it out.

Ultimately I am unable to echo out a session and it does not seem anything is being made.

If you could help me out that would be awesome because I need this finished! :)

  • 写回答

1条回答 默认 最新

  • dsfovbm931034814 2012-12-19 21:15
    关注

    You need to clarify the program flow. What loads what, when?

    "I am trying to have a JSON send over a value". JSON is a data format, not a method. JSON cannot send anything, it can be sent.

    If you debug the JavaScript (use the Chrome developer tool or Firebug in Firefox), do you have the product name in your onclick function?

    $('.item-post a').click(function() {
        var prodname = $('#hiddenpostitle');
        alert(prodname.val());
    

    (you can inspect network traffic, or set a breakpoint on the "var prodname ..." line and simply add a watch on prodname, hover it etc, to see if you have the correct product name)

    Next, see what you got on the server side from the AJAX request.

    <?php
    
    /* Template Name: overviewbackcheck */
    
    session_start();
    var_dump($_POST);die; // You can see what is dumped here in the Network tab in the browser's Developer tool.
    

    If you don't know how to use browser debug tool, you could always save to the error log and read that instead.

    <?php
    error_log(print_r($_POST, true));
    

    Finally when you fetch the code from "../overviewa512454dzdtfa", does that script do session_start(); before you do this?

    <?php echo $_SESSION['overviewprod']; ?>
    

    Compared to

    <?php session_start(); echo $_SESSION['overviewprod']; ?>
    

    Don't have any more ideas at this time, keep at it.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序