doumubi6784 2015-04-05 14:24
浏览 31
已采纳

PHP中的jQuery Ajax和POST方法

I have two files basic.php and pptimeline.php. The purpose here is to select a value from a combobox in basic.php, process it in the pptimeline.php and print it back in basic.php. But I'm not having success in doing so. If anyone can help I appreciate.

EDIT: The pptimeline.php file acts as a json file header('Content-Type: application/json');. It has only querys which I then echo in the file but are not relevant here since everything works if I use default values instead of $nprocess in the query. The code that displays my data is inside the sucess: parameter in basic.php. If I remove what is around it everything works fine, but then it doen'st change based on what I choose.

Basic.php

<label for="Process"> NProcess : </label>
<select id="cproc">
  <?php
foreach ($products as $res3)
    {echo "<option value='".$res3["PROCESSO"]."'>".$res3["PROCESSO"]."</option>";}
    ?>
    </select>
<script type='text/javascript'> 
    $("#cproc").on("change", function(){
        var v1 = $(this).val();
        $.ajax({
            url: "pptimeline.php", 
            type: "POST", 
            data: {'value' : v1}, 
            success: function(response){

            /**DISPLAY DATA IN INTERFACE**/
             var tg1 = {};
    $(function () { 
        // jQuery widget implementation
        // with some basic options
        tg1 = $("#placement").timeline({
                "min_zoom":1, 
                "max_zoom":55, 
                "image_lane_height":100,
                "icon_folder":"timeglider/icons/",
                "data_source":"pptimeline.php",
                "constrain_to_data": false
        });
        tg_actor = tg1.data("timeline");
        // You'll use tg_actor as the key to access 
        // public API methods like "goTo", etc.         
    }); // end document-ready
                      /****/

   }, error: function(x,y,z){
                alert("error"); } }); }); 
</script>

pptimeline.php

if (isset ($_POST['value'])) {
    $nprocesso = $_POST['value'];

$query1 = "SELECT TO_CHAR(DATACRIACAO,'YYYY-MM-DD') AS DATACRIACAO, NPROCESSO, 
BLOCOOPERATORIO, TIPOINTERNAMENTO, TIPOINTERNAMENTOCIRURGIA, GLASGOW_HOSPITAL 
FROM PATIENT_TIMELINE_ADMISSAO WHERE NPROCESSO =".$nprocesso."";
}
  • 写回答

1条回答 默认 最新

  • doujiunai2169 2015-04-05 17:25
    关注

    Your $.ajax() call is unnecessary. Remove it, and just add your selected value to the .timeline() data_source-

    <script type='text/javascript'> 
        $("#cproc").on("change", function(){
            var v1 = $(this).val();
            var tg1 = {};
            $(function () { 
                // jQuery widget implementation
                // with some basic options
                tg1 = $("#placement").timeline({
                    "min_zoom":1, 
                    "max_zoom":55, 
                    "image_lane_height":100,
                    "icon_folder":"timeglider/icons/",
                    "data_source":"pptimeline.php?value="+v1, //add select value to url
                    "constrain_to_data": false
                });
                tg_actor = tg1.data("timeline");
                // You'll use tg_actor as the key to access 
                // public API methods like "goTo", etc.         
            }); // end document-ready
        }); 
    </script>
    

    Then change your php code from $_POST to $_GET

    if (isset ($_GET['value'])) {
        $nprocesso = $_GET['value']; //make sure to sanitize value to prevent SQL injection
    
        $query1 = "SELECT ... NPROCESSO =".$nprocesso."";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看