javascript - I want to post data from HTML file to php and how to redirect to the php and show data in php -


i post data html file php file , how redirect php file , see data in console page.

i beginner , not in ajax. please check below code have used.

i want send json data php file. question how post json data php , see data in php file. got error states undefined index postcountry.

my question how solve error. please me correct mistake.

thank you.

in ajax.html

    <html>      <head>      <title> new ajax</title>      <script type="text/javascript" src="/cesium-1.34/thirdparty/jquery-      1.11.3.min.js"></script>      </head>      <body>       <h2>show data in php</h2>       <br />       <br />       <form>        <input type="hidden" id="country" value="singapore" readonly>        <input type="hidden" id="time" value="141253" readonly>        <input type="button" value="submit me" onlcick="showdata();">       </form>       <div id="resulte"></div>     <h3>look @ console. click ctrl + shift + j view console page.     </h3>     <script type="text/javascript">      var country = document.getelementbyid("country");      var time = document.getelementbyid("time");      function showdata() {        $.ajax({          type: "post",          datatype:  "json",          url: "abdullahpass.php",         //async: false,          data: json.stringfy({postcountry: country,          posttime: time}),          success: function(data) {             console.log(data);            },          error: function(jqxhr, textstatus, errorthrown) {             alert('an error occurred... @ console (f12 or              ctrl+shift+i, console tab) more information!');             $('#resulte').html('<p>status code: '+jqxhr.status+'</p>             <p>errorthrown: ' + errorthrown + '</p><p>jqxhr.responsetext:</p>             <div>'+jqxhr.responsetext + '</div>');             console.log('jqxhr:');             console.log(jqxhr);             console.log('textstatus:');             console.log(textstatus);             console.log('errorthrown:');             console.log(errorthrown);           },        });     }     </script>     </body>     </html> 

in file

      <?php          echo json_decode($_post['posttime']);          echo json_decode($_post['postcountry']);          echo var_dump($_post);       ?> 

//in ajax call data no need strigyfy data.

<script type="text/javascript">          var country = document.getelementbyid("country");          var time = document.getelementbyid("time");          function showdata() {            $.ajax({              type: "post",              datatype:  "json",              url: "abdullahpass.php",             //async: false,              data: {postcountry: country,posttime: time},              success: function(data) {                 console.log(data);                },              error: function(jqxhr, textstatus, errorthrown) {                 alert('an error occurred... @ console (f12 or                  ctrl+shift+i, console tab) more information!');                 $('#resulte').html('<p>status code: '+jqxhr.status+'</p>                 <p>errorthrown: ' + errorthrown + '</p><p>jqxhr.responsetext:</p>                 <div>'+jqxhr.responsetext + '</div>');                 console.log('jqxhr:');                 console.log(jqxhr);                 console.log('textstatus:');                 console.log(textstatus);                 console.log('errorthrown:');                 console.log(errorthrown);               },            });         }         </script> 

i got error states undefined index postcountry not error warning, using isset function can overcome same , $_post['posttime'] , $_post['postcountry'] values. should use json_encode on array only.

    <?php           echo (isset($_post['posttime']) && $_post['posttime']) ? $_post['posttime'] : 'no value posttime';          echo (isset($_post['postcountry']) && $_post['postcountry']) ? $_post['postcountry'] : 'no value postcountry';            //this print total post data type          echo var_dump($_post);       ?> 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -