2017-10-16 8 views
1

私はこのコードに問題があります。 btn_verifyボタンを押して「これはJSONです」というメッセージが表示されます。奇妙なことはプログラムが実行されていることですlocalhostに がありますが、ホストへのアップロードが実行されず、メッセージが表示されない場合 理由は何ですか? 私は、同じ構造とライブラリを使用し、両方の形式でよく実行される のプログラムを持っています:ローカルとホスティング。JSON AJAX php onlineを使用してメッセージを表示しない

私のコードは次のとおりです。

// HTML

<!DOCTYPE html> 
<html> 
<head> 
    <title>Resultados</title> 

<style type="text/css"> 
td{font-family: Arial; font-size: 9pt;} 
</style> 

<style type="text/css"> 
    th{font-family: Arial; font-size: 9pt;} 
</style> 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="viewport" content="width=device-width, initial-scale=1" /> 
<link rel="stylesheet" href="public/css/bootstrap.min.css" /> 
</head> 
<body> 

<button type="button" name="btn_verificar" id="btn_verificar" class="btn 
btn-info">Verificar</button> 

<div class="the-return"> 

</div> 

<script src="public/js/jquery-3.1.1.js"></script>       
<script src="public/js/bootstrap.min.js"></script> 
<script type="text/javascript" src="script/functions.js"></script> 

    <script> 
    $(document).on('click','#btn_verificar',function(){ 
     $(document).ready(function(){ 
     $('#btn_verificar').click(function(){ 

     var id=$('#id_pedido').val();//take id about one record and it is ok 

     //alert(id); show id and this out it's right 

     $.ajax({ 
     method:"POST", 
     url:"verificarResultados.php",   
     data:{id:id}, 
     dataType:"JSON",   
     success:function(data) 
      {    
      alert(data.result); 

      $(".the-return").html("Message:" + data["result"]); 

      }//end success   
     }); //end ajax 
    });// end document ready 
    });//end on click 

</script> 
</body> 
</html> 



//file verificarResultados.php 

<?php 

    if(isset($_POST["id"])) 
    {  
    $rows = array("result" => 'This is JSON'); 
    echo json_encode($rows);    
    } 
?> 
+1

あなたは、あなたのブラウザのWebコンソールで探してみたのですか? – Miggy

+0

アラートは機能しますか?あなたはデータをログに記録できますか?あなたのコンソールのネットワークタブを見て、送信されたものと受信されたものを見ることができますか? .click関数内にdocument.readyがあるのはなぜですか?コンソールでJavaScriptエラーが発生しますか? – Andrew

+0

https://stackoverflow.com/help/mcve – Andrew

答えて

0
$.ajax({ 
     method:"POST", 
     url:"verificarResultados.php",   
     data:{id:id}, 
     dataType:"JSON", 
     success: function (data) { 
      alert(data.result); 
     }, 
     error: function (xhr, result, error) { 
      alert(xhr.responseText); 
     } 
    }); 
関連する問題