dtnmuyoiw680512744 2016-06-06 05:10
浏览 41
已采纳

如何使用JQuery Ajax将数据发送到PHP文件?

I am trying to send data to php file using jQuery and ajax. However, I am only able to receive the response from ajax in json format and unable to send data.

    $.ajax({
        url: 'myFile.php',
        type: 'GET',
        data: {ID:1}, 
        dataType:'json',
        cache: false,
        beforeSend:function(e){},
        processData: '',
        success: function(response){
            Initialize(response);   
        },
        error: function(err){alert('error')}
    });
  • 写回答

1条回答 默认 最新

  • dongyanju0945 2016-06-06 06:13
    关注

    You already done everything ok.

    $.ajax({
      url: 'myFile.php',
      type: 'GET',
      data: {
        ID: 1,
        Test: 'Anothervalue'
      },
      dataType: 'json',
      cache: false,
      beforeSend: function(e) {},
      processData: '',
      success: function(response) {
        Initialize(response);
      },
      error: function(err) {
        alert('error')
      }
    });
    

    Using php you can get those value by

    $_GET['ID'] $_GET['Test']

    You can send data by concating with url also

    myFile.php?ID=1&Test=Anothervalue

    But if want send data with POST or have much data to send you can always choose data: {} format to send because it's cleaner.

    data: {
        ID: 1,
        Test: 'Anothervalue',
        // More
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 milvus查询出来的score怎么转换成0-1之间的相似性
  • ¥15 多ip服务器站群如何搭建l2tp服务器
  • ¥15 lvgl V9移植到linux开发板
  • ¥15 VB.net中在窗体中创建一个button控件来关闭窗体,但是提示错误,我该怎么办
  • ¥15 网上下载好的程序但是arduinoIDE编程报错,运行不了,哪里出错了,能具体给改一下吗
  • ¥15 Sharepoint JS开发 付费技术指导
  • ¥15 输入程序运行仿真后,烟雾值不实时检测,变成固定值
  • ¥20 数据排序,可选择排序方向
  • ¥15 修改一下代码,考虑进程到达时间不同的情况
  • ¥15 帮我看看这是个啥题,带解题过程和结果,条件如下FCF = 290471.33 g1 = 15% r = 8% g2 = 4% n = 5