dongtan3395 2015-09-23 13:31
浏览 58
已采纳

使用javascript将数据($ post)传递给php文件,无需回调

I need to pass data from HTML page to PHP page But without data callback ....

i'm used two method but One of them did not succeed

1)

$.ajax({
    type: "POST",
    url: 'phpexample.php',
    data: {voteid: x },
    success: function(data)
    {
        alert("success! X:" + data);
    }
});

2)

$.post("getClassStudent.php",
{
},
function(data){
    $("#div_id.php").html(data);

    }
);
  • 写回答

2条回答 默认 最新

  • duanba7653 2015-09-23 16:30
    关注

    as i can understand, you just want to send info to a php script and don't need the response, is that right?

    try this

    $.post("phpexample.php", {voteid:x});
    

    or simply remove the "succes" function from the equation if you feel more confortable using $.ajax instead of $.post

    $.ajax({
        type: "POST",
        url: 'phpexample.php',
        data: {voteid: x }
    });
    

    your fisrt example is correct, the second is not well formed.

    more info:

    http://api.jquery.com/jquery.post/

    EDIT: to help you some more :)

    <button type="button" id="element-id">click</button>
    
    <button type="button" class="class-name">Click</button>
    
    $(document).ready(function(){ 
        //if you are marking ans element by class use '.class-name'
        $(".class-name").click(function(){ 
           $.post("getClassStudent.php"); 
        }); 
        //if marking by id element use '#id-name'
        $("#element-id").click(function(){ 
           $.post("getClassStudent.php"); 
        }); 
    });
    

    be carefful with the markings, for debuggin try to use "console.log()" or "alert()" so you can see where is the problem and where the code crushes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line