weixin_33725807 2017-09-13 22:17 采纳率: 0%
浏览 18

我的ajax根本不起作用?

I have an AJAX function (below). I am trying to pass an input from one page to another.

It redirects me to the other page but does not pass the required value.

I do not understand why it doesn't work as I expected.

I am looking for another way to do this. Any help will be appreciated.

  //second page
  
  <?php
     $cuit = $_POST['cuit'];
    ?>
<input id="act" type="text" class="form-control" value="<?php echo $cuit ?>">

function mod(id, origen) {
  swal({
    title: 'Are you sure?',
    text: "You won't be able to revert this!",
    type: 'warning',
    showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!',
    cancelButtonText: 'No, cancel!',
    confirmButtonClass: 'btn btn-success',
    cancelButtonClass: 'btn btn-danger',
    buttonsStyling: false
  }).then(function() {
    if (origen == "perfiles") {
      $.post("api/eliminar_perfil.php", {
        id: id
      }, function(mensaje) {
        $("#tr_" + id).remove();
      });
    } else if (origen == "index") {
      $.ajax({
        type: "post",
        url: "perfiles.php",
        data: {
          cuit: $("#cuit").val()
        },
        success: function(result) {
          location.href = 'http://localhost/miramonteapp/perfiles.php';
        }
      });
    }
    swal('Deleted!', 'Your file has been deleted.', 'success')
  }, function(dismiss) {
    // dismiss can be 'cancel', 'overlay',
    // 'close', and 'timer'
    if (dismiss === 'cancel') {
      swal('Cancelled', 'Your imaginary file is safe :)', 'error')
    }
  })
}
<input id="cuit" type="text" class="form-control" onkeyup="searchCliente();">

<button id="btnBuscar" onclick="mod($('#cuit'), 'index');" type="button" class="btn btn-default" name="button">Buscar</button>

</div>
  • 写回答

1条回答 默认 最新

  • 喵-见缝插针 2017-09-13 22:29
    关注

    Boy, I think your solution is simpler, you don't need the ajax call if you want to redirect with a param.

    so replace this

     $.ajax({
                   type : "post",
                   url : "perfiles.php",
                   data :  {cuit: $("#cuit").val()},
                   success : function(result) {
                    location.href = 'http://localhost/miramonteapp/perfiles.php';
                   }
                 });
    

    by this

     location.href = 'http://localhost/miramonteapp/perfiles.php?cuit=' + 
     $("#cuit").val();
    

    and in your destination page perfiles.php

    just read the param and use it, you can read params in JS using this as a guide How to get the value from the GET parameters?

    评论

报告相同问题?

悬赏问题

  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器