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 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数