douyou7072
2014-07-01 23:59
浏览 10

如何在URL中转换此JavaScript

I have this code :

function name() {
    $.ajax({
      type: "POST",
      url: "/index.php",
      data: { id:  $("#id").val(),  date: new Date().getTime()}, 
    }); 
}

I would like to understand what is the translation to put in a URL. I have tried everything and it doesn't work. In my mind, it should be index.php?id= ... but no.

图片转代码服务由CSDN问答提供 功能建议

我有这段代码:

  function name(){  
 $ .ajax({
 type:“POST”,
 url:“/ index.php”,
 data:{id:$(“#id”)。val(),日期:新日期(  ).getTime()},
});  
} 
   
 
 

我想了解放入网址的翻译是什么。 我已经尝试了一切,但它不起作用。 在我看来,它应该是 index.php?id = ... 但不是。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doukuang8166 2014-07-02 00:15
    已采纳

    an alternative would be:

    function name() {
        $.get('index.php?id=' + $("#id").val() +'&date ='+ new Date().getTime() +'',function(data){
            //work with the data callback here.
        });
    }
    
    已采纳该答案
    打赏 评论
  • duanbipu1720 2014-07-02 00:10

    Try this :

    function name() {
        $.ajax({
          type: "GET",
          url: "/index.php",
          data: { id:  $("#id").val(),  date: new Date().getTime()}, 
        }); 
    }
    

    And receive id and date with $_GET['id'] , $_GET['date']...

    If you use POST type, You have to receive with $_POST.

    打赏 评论

相关推荐 更多相似问题