dsjswclzh40259075 2013-09-02 11:50
浏览 62
已采纳

我想将一个jquery变量传递给PHP页面,有时我得到的是变量,有时候不是

I have a PHP page named logo_design_3.php. I have used Jquery to post the variable "grand_total" to another page named logo_design_3_sql.php. But unfortunately sometimes i'm getting that variable on the next page and sometimes not. Any idea where i'm doing wrong?

Here is the snippet of logo_design_3.php page:

<script type="text/javascript">
function load1() {
    document.getElementById('hide2').style.display = 'none';
    return false;
}

function toggle() {
    document.getElementById('hide1').style.display = 'none';
    document.getElementById('hide2').style.display = '';
    document.getElementById('hidrad').checked = 'true';
    document.getElementById('silver').checked = false;
    document.getElementById('bronze').checked = false;
    document.getElementById('gold').checked = false;
}

function load2() {
    document.getElementById('hide1').style.display = '';
    document.getElementById('hide2').style.display = 'none';
}
</script>
<script type="text/javascript">
$(document).ready(function() {

    var grand_total = 0;

    $("input").live("change keyup", function() {

        $("#Totalcost").val(function() {

            var total = 0;
            $("input:checked").each(function() {

                total += parseInt($(this).val(), 10);
            });
               var textVal = parseInt($("#min").val(), 10) || 0;

               grand_total = total + textVal;

               return grand_total;
        });

     });
         $("#next").live('click', function() {

        $.ajax({
            url: 'logo_design_3_sql.php',
            type: 'POST',
            data: {
                grand_total: grand_total
            },
            success: function(data) {
                // do something;

            }
        });

    });

});
 </script>
 <script type="text/javascript">
function validate() {
    var num = document.getElementById("min").value;
    var num = parseInt(num, 10);

    if (num < 299) {
        document.getElementById("min").value = "299";
        alert("Minimum Amount Should be 299");
    }
}

</head>
<body onLoad="load1()">
<div id="wrap">
<div class="main-container internal">
<div class="main wrapper clearfix section">
<article>
<section>
                     <h1>Step 3. Contest details</h1>

                     <h2>Create a contest that attracts the right designers to your brief.</h2>

                    <p>We've got the largest design community online so it's important to create a contest that attracts the kinds of designers you want to work on your brief.</p>
                    <div id="form">
                        <form method="post" id="logoform3" action="logo_design_3_sql.php">
                            <label>What design package do you want?</label>
                            <br>All packages come with a 100% money-back guarantee and you own full copyright to the final design.
                            <br>
                            <p></p>
                            <p>
                                <input type="radio" class="radio" name="b" onClick="load2()" value="299" id="bronze">
                                <label>Bronze - $299</label>
                                <br>Get lots of great designs at a great price
                                <br>
                                <li style="list-style:circle">Expect around 30 designs</li>
                            </p>
                            <p>
                                <input type="radio" class="radio" name="b" onClick="load2()" value="499" id="silver">
                                <label>Silver - $499</label>
                                <label class="block badge">Most popular</label>
                                <br>Attract great designers and get priority support
                                <br>
                                <li style="list-style:circle">Your project will be shown to designers before bronze projects</li>
                                <li style="list-style:circle">Expect around 60 designs</li>
                            </p>
                            <p>
                                <input type="radio" class="radio" name="b" onClick="load2()" value="799" id="gold" checked="true">
                                <label>Gold - $799</label>
                                <label class="block badge">Work only with our top designers</label>
                                <br>Work only with our most talented designers and receive 1-on-1 support
                                <br>
                                <li style="list-style:circle">Only our best designers can participate to ensure top quality</li>
                                <li style="list-style:circle">A dedicated account manager will guide you to the best result possible</li>
                                <li style="list-style:circle">Expect around 60 designs of the highest quality</li>
                            </p> <a onclick="toggle(); event.preventDefault();" href="#" style="text-decoration:none;border-bottom:1px dotted blue;" id="hide1">I want to create a custom package</a>

                            <br>
                            <div id="hide2">
                                <p>
                                    <input type="radio" class="radio" name="bbb" id="hidrad" checked="true" id="name_ur_price" value="0">Name your price:
                                    <input type="number" width="10px" style="background:#ccc; border:1px solid #ccc !important;" id="min" min="299" name="min" onChange="validate();" id="name_your_price" name="name_your_price">.00($299 minimum)
                                    <br>
                                </p>
                            </div>
                            <label>Contest preferences</label>
                            <br>
                            <input type="checkbox" name="" value="39.00" align="middle" id="private_contest" name="private_contest">
                            <label>Make your contest private (+$39.00)</label>
                            <br>Your contest will be hidden from search engines and the general public. Only members of the Square Designs community can see your contest and they must agree to a Non-Disclosure Agreement (NDA) to see the details. We provide a standard template for the NDA or <a href="" onclick="document.getElementById('upload').click(); return false"> you can upload your own(as a PDF).</a>

                            <br>
                            <input type="file" id="upload" name="upload" style="visibility: hidden; width: 1px; height: 1px" multiple />
                            <label id="design_dura" style="left:!important">How quickly do you need your design?</label>
                            <br>
                            <br>
                            <input type="radio" name="c" value="0">
                            <label>Standard 7 days (FREE)</label>
                            <br>
                            <input type="radio" name="c" value="39" id="days_3">
                            <label>In 3 days(+$39.00)</label>
                            <br>
                            <input type="radio" name="c" value="59" id="days_2">
                            <label>In 2 days(+$59.00)</label>
                            <br>
                            <label>
                                <input type="radio" name="c" value="79" id="days_1">In 24 hours(+$79.00)</label>
                             <h2>TOTAL :</h2>

                            <p>
                                <input type="text" name="Totalcost" id="Totalcost" style="background:#f5f5f5; border:none; outline:none; box-shadow:none; font-size:18px;" disabled/>
                                <br>
                            </p>
                            <input type="submit" class="sumit-styled" value="Next" style="margin-left:-15px;" id="next" name="next">
                            <input type="submit" class="sumit-styled" value="Save Now" style="margin-left:-15px;" id="save" name="save">
                        </form>
                    </div>
                </section>
                <aside>
                    <img src="img/slide2_2.png" webstripperwas="img/slide2_2.png" alt="mockup" />
                    <p><em>Donec sed odio dui. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.</em>

                    </p>
                </aside>
            </article>
            <!-- END MAIN -->
        </div>
    </div>
</div>

And this is from logo_design_3_sql.php page:

<?php include ( "config.php"); 
$total=$_POST[ 'grand_total'];
 $sql="INSERT INTO form2 (total)VALUES('$total')" ; 
if($total>0)
{ $res = mysql_query($sql); } 
if($res) 
{ echo "<script> window.location.replace('logo_design_4.php')</script>"; }
 else { echo "<script> window.location.replace('logo_design_3.php')</script>"; }
 ?>

I have issue regarding -> window.location.replace('logo_design_4.php') too. Even if $total is properly inserted in the table, the page that get navigated after insertion is "logo_design_3.php". Why so?

  • 写回答

2条回答 默认 最新

  • dongnue2071 2013-09-02 11:53
    关注

    please try live function as below

    $("#next").live('click',function () {
        $.ajax({
                url: 'logo_design_3_sql.php',
                type: 'POST',
                data: {grand_total: grand_total},
                success: function(data) {}
            });
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛