我的阿贾克斯根本不工作?

时间:2017-09-13 22:17:56

标签: javascript jquery html ajax

我有一个AJAX功能(如下)。我试图将输入从一个页面传递到另一个页面。

它将我重定向到另一页但未传递所需的值。

我不明白为什么它没有像我预期的那样工作。

我正在寻找另一种方法来做到这一点。任何帮助将不胜感激。



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

&#13;
&#13;
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')
    }
  })
}
&#13;
<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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

男孩,我认为您的解决方案更简单,如果您想使用参数重定向,则不需要ajax调用。

所以替换这个

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

由此

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

并在您的目标网页 perfiles.php

只需阅读参数并使用它,您可以使用此作为指南阅读JS中的参数How to get the value from the GET parameters?

相关问题