doubi9615 2012-07-06 13:33
浏览 62
已采纳

如何在jQuery AJAX函数中使用'data:'?

I'm using this jQuery AJAX function and I'm trying to figure out how to use the 'data:' part of it. According to this page (http://api.jquery.com/jQuery.ajax/) I can use 'data:' to send the number 22 to 'process_stage.php' so I can use it.

Can anyone tell me what I need to type in my process_stage.php page to access the number 22?

function myAJAX(){
$.ajax({                                      
url: 'process_stage.php',     
      data: '22',    
      dataType: 'json',                             
      success: function(data) {             
        var videoid = data[0];      
        var currentID = data[1];
        $('#youtube').html("<iframe width='400' height='225' src='http://www.youtube.com/embed/"+videoid+"?rel=0&amp;autohide=1&amp;showinfo=0&amp;autoplay=1' frameborder='0' allowfullscreen></iframe>");
        setTimeout(function (){
            timedCount(currentID);
            },1000);
        }
});
}
  • 写回答

2条回答 默认 最新

  • douba4275 2012-07-06 13:36
    关注

    As you're making a HTTP GET request, data needs to be key-value pairs, as that's how a GET request is constructed (e.g. /get.php?var1=a&var2=b&var3=c).

    jQuery.ajax() accepts this key-value pairs as either an object map, or a string, as described in the documentation:

    Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below).

    So you should use either;

    data: "value=22"
    

    or

    data: {
        value: 22
    }
    

    Then in PHP you can use $_GET['value'] to retrieve it.

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

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口