weixin_33709364 2013-08-14 19:24 采纳率: 0%
浏览 22

javascript到ajax到php

Need help. I have a page called edit.php. I am trying to send a javascript variable to a modal window that contains php, so that I can run a query to pull data. I don't have much experience with ajax, and I couldn't find a good tutorial for this.

Here is my javascript code with an attempted ajax call:

 <script type="application/javascript">
 $(document).on("click", ".open-EditRow", function () {
   var myGroupId = $(this).data('id');
   $(".modal-body #groupId").val( myGroupId );

   // ajax call
   var url = "" + myGroupId;
   $.get(url, function(data){
   // do something here
   });
 });
 </script>

I know I need to create a separate folder with a file that will convert myGroupId into a PHP variable.

Here is the modal that the myGroupId should be returned to:

 <div class="modal hide fade" id="myEditModal" tabindex="-1" role="dialog" aria-labelleby="myModalLabel" aria-hidden="true">
 <div class="modal-body">
 <form class="well-small" action="" method="POST" id="modalForm" name="modalForm">
 <?php 
   // here is where I need myGroupId returned to
 ?>
 </form>
 </div>
 </div>

Can anyone give me an example of how that separate file should look and how to send it back to the modal on my edit.php file?

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • 游.程 2013-08-14 19:28
    关注

    You forgot to add a key to your URL. This should work:

    var url = "?groupid=" + encodeURIComponent(myGroupId);
    $.get(url, function(data){ // etc.
    

    But jQuery can take care of encoding for you if you do it like this:

    $.get(url, {groupid: myGroupId}, function(data){ // etc.
    

    You'll then be able to read it in PHP with $_GET['groupid'].

    Reference: jQuery.get

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘