Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ajax未将数据发送到php_Php_Ajax_Postgresql - Fatal编程技术网

ajax未将数据发送到php

ajax未将数据发送到php,php,ajax,postgresql,Php,Ajax,Postgresql,我有一个函数,用于将数据发送到php文件。虽然我收到一个显示正确ID和成功消息的警报,但在我的process.php中尝试回显时,什么也没有显示。该函数位于引用process.php的文件adopt.php中: <script type="text/javascript"> $(function(){ $('#loginform').submit(function(e){ return false; }); <?php

我有一个函数,用于将数据发送到php文件。虽然我收到一个显示正确ID和成功消息的警报,但在我的process.php中尝试回显时,什么也没有显示。该函数位于引用process.php的文件adopt.php中:

 <script type="text/javascript">
    $(function(){
      $('#loginform').submit(function(e){
        return false;
      });

   <?php
        $q = pg_query($conn, "SELECT * FROM caini_donati");
            while($res = pg_fetch_assoc($q)){ ?>
                $('#<?php echo $res['id_caine']; ?>').leanModal({ top: 110, overlay: 0.45, closeButton: ".hidemodal" }); 
    $("#<?php echo $res['id_caine']?>").click(function(event) {            
        var id_caine = event.currentTarget.id;            
        alert(id_caine);
        $.ajax({                
            type: 'POST',
            url: 'process.php',                                                
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            data: { id_caine : id_caine},                                
            success: function(data){
                alert("succes"),
                console.log(data);
            }, error: function(xhr, ajaxOptions, thrownError) {alert ("Error:" + xhr.responseText + " - " + thrownError );}

        });                       
    });                   
        <?php } ?> 
    }); 
</script>

 in process.php i have:
<?php
    $var = $_POST['id_caine'];
    echo "tr1: ".$_POST['id_caine'];
    echo "try: ".$var;
 ?>

$(函数(){
$('#loginform')。提交(函数(e){
返回false;
});
$('#').leanmodel({top:110,overlay:0.45,closeButton:“.hidemodal”});
$(“#”)单击(函数(事件){
var id_caine=event.currentTarget.id;
警报(id_caine);
$.ajax({
键入:“POST”,
url:'process.php',
contentType:“application/x-www-form-urlencoded;charset=UTF-8”,
数据:{id_caine:id_caine},
成功:功能(数据){
警报(“成功”),
控制台日志(数据);
},错误:函数(xhr,ajaxOptions,thrownError){alert(“错误:+xhr.responseText+”-“+thrownError);}
});                       
});                   
}); 
在process.php中,我有:

有人知道我做错了什么吗?在process.php中,我想基于'id_caine'变量运行一个更新查询..任何想法都是值得的..不重要,但我对ajax一无所知。

RiggsFolly是正确的,您缺少javascript html标记,我调整了您的代码以显示它们应该在哪里。我还修改了success方法,这样实际上就有了一个变量。您将rs定义为参数,但随后尝试使用“数据”


$('#').leanmodel({top:110,overlay:0.45,closeButton:“.hidemodal”});
$(“#”)单击(函数(事件){
var id_caine=event.currentTarget.id;
警报(id_caine);
$.ajax({
url:'process.php',
键入:“POST”,
数据:{id_caine:id_caine},
数据类型:“html”,
成功:功能(数据){
警报(“成功”),
控制台日志(数据);
},错误:函数(xhr,ajaxOptions,thrownError){alert(“错误:+xhr.responseText+”-“+thrownError);}
});                       
});

将url更改为:“/process.php”将向我显示一个错误警报,指出服务器上找不到该页面。您的问题是,您试图在服务器上执行javascript,而您应该在
块内将该js回送到浏览器,以便在浏览器上运行。好的,明白了…但我是否可以将变量发送到php,并根据该变量运行更新查询?您的JQuery代码看起来不错,只是它没有发送到浏览器,所以它从来没有实际运行过。我知道,这非常令人沮丧。无论如何,谢谢!我不知道为什么,但在添加帖子时,我完全忘记了之前也添加了标签..我在5个多小时内都在尝试解决这个问题,很抱歉我的错误,还有rs变量..不知道我是如何忽略了…无论如何…仍然不起作用:)…我修改了你的评论..谢谢!嗯,非常奇怪,这是我用来测试的代码,我去掉了postgress调用,删除了与dom元素的绑定,下载并将其保存为test.php本地或在您的服务器中,然后在那里进行测试。我很好奇它在控制台中的输出是什么。我做到了!!谢谢你们!我想我是要放弃了..按照你的建议,我在浏览器控制台中查看了输出,发现变量实际上是在控制台中回送的,但是当访问process.php时,它仍然不可用..我无法解释为什么,但我还是基于变量运行了我的查询..还有一件事..我不知道它是否有任何影响,但我使用了数据:{'id_caine':id_caine}而不是数据:{id_caine:id_caine}…非常感谢!!!
<?php
    $q = pg_query($conn, "SELECT * FROM caini_donati");
    while($res = pg_fetch_assoc($q)){ ?>
    <script type="text/javascript">
        $('#<?php echo $res['id_caine']; ?>').leanModal({ top: 110, overlay: 0.45, closeButton: ".hidemodal" }); 
        $("#<?php echo $res['id_caine']?>").click(function(event) {            
            var id_caine = event.currentTarget.id;
            alert(id_caine);
            $.ajax({
                url: 'process.php',
                type: 'POST',                
                data: { id_caine : id_caine},                
                dataType: 'html',
                success: function(data){
                    alert("succes"),
                    console.log(data);
                }, error: function(xhr, ajaxOptions, thrownError) {alert ("Error:" + xhr.responseText + " - " + thrownError );}                
            });                       
        });
    </script>
<?php } ?>