douou9786 2011-05-24 12:07
浏览 77

使用Jquery AJAX将Javascript变量传递给PHP

I have the following javascript function

function success_callback(p)
    {

        lat = p.coords.latitude.toFixed(2);
        lon = p.coords.longitude.toFixed(2);

    }

Now I want to transfer both the variable to PHP using Jquery AJAX, I am pretty new to Jquery, I am not able to figure out how to do it. I want to transfer the variables to the same PHP file where this JS code resides. Is that possible ?

  • 写回答

4条回答 默认 最新

  • douyue8364 2011-05-24 12:11
    关注

    Yes it is. You could post the variables using the data string. Have a look at the Manual.

    $.ajax({
      type: "POST",
      data: "lat="+lat+"&lon="+lon,
      success: function(){
          //callback code
          alert("Done!");
      }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置