发布数据时停止页面重新加载

时间:2017-05-29 01:21:39

标签: javascript ajax post submit reload

我必须将数据发布到php,但是当我这样做时,页面会重新加载。我尝试使用类似问题给出的答案来解决这个问题,但没有一个能产生正确的结果。谢谢你的帮助。

17/05/29 08:42:50 INFO cluster.YarnScheduler: Removed TaskSet 6.0, whose tasks have all completed, from pool
17/05/29 08:42:50 INFO scheduler.DAGScheduler: ResultStage 6 (run at AccessController.java:0) finished in 2.567 s
17/05/29 08:42:50 INFO scheduler.DAGScheduler: Job 3 finished: run at AccessController.java:0, took 2.819549 s
17/05/29 08:42:51 INFO metastore.HiveMetaStore: 6: get_table : db=task tbl=task_107
17/05/29 08:42:51 INFO HiveMetaStore.audit: ugi=root    ip=unknown-ip-addr  cmd=get_table : db=task tbl=task_107    
17/05/29 08:42:51 INFO metastore.HiveMetaStore: 6: get_table : db=task tbl=task_107
17/05/29 08:42:51 INFO HiveMetaStore.audit: ugi=root    ip=unknown-ip-addr  cmd=get_table : db=task tbl=task_107    
17/05/29 08:42:51 INFO metastore.HiveMetaStore: 6: get_database: task
17/05/29 08:42:51 INFO HiveMetaStore.audit: ugi=root    ip=unknown-ip-addr  cmd=get_database: task  
17/05/29 08:42:51 INFO metastore.HiveMetaStore: 6: get_table : db=task tbl=task_107
17/05/29 08:42:51 INFO HiveMetaStore.audit: ugi=root    ip=unknown-ip-addr  cmd=get_table : db=task tbl=task_107    
17/05/29 08:42:51 INFO metastore.HiveMetaStore: 6: get_database: task
17/05/29 08:42:51 INFO HiveMetaStore.audit: ugi=root    ip=unknown-ip-addr  cmd=get_database: task  
17/05/29 08:42:51 INFO metastore.HiveMetaStore: 6: get_table : db=task tbl=task_107
17/05/29 08:42:51 INFO HiveMetaStore.audit: ugi=root    ip=unknown-ip-addr  cmd=get_table : db=task tbl=task_107    
17/05/29 08:42:51 INFO metastore.HiveMetaStore: 6: drop_table : db=task tbl=task_107
17/05/29 08:42:51 INFO HiveMetaStore.audit: ugi=root    ip=unknown-ip-addr  cmd=drop_table : db=task tbl=task_107   
17/05/29 08:42:51 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table.
17/05/29 08:42:51 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table.
17/05/29 08:42:51 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table.
17/05/29 08:42:51 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table.
17/05/29 08:42:51 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table.
17/05/29 08:42:51 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table.
17/05/29 08:42:52 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table.
17/05/29 08:42:52 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table.
17/05/29 08:42:52 INFO metastore.hivemetastoressimpl: deleting  hdfs://jzf-01:9000/user/hive/warehouse/task.db/task_107
17/05/29 08:42:52 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0 minutes, Emptier interval = 0 minutes.
17/05/29 08:42:52 INFO metastore.hivemetastoressimpl: Deleted the diretory hdfs://jzf-01:9000/user/hive/warehouse/task.db/task_107
17/05/29 08:42:52 ERROR thriftserver.SparkExecuteStatementOperation: Error executing query, currentState RUNNING,

我推荐的另一种方法是使用ajax:

<!--HTML-->
<form method="post" action="index.php" onclick = "sendForm(event);">            
   <input type="text" class="form-control" id="code" name="rand5_code">
    <input type="submit" href=""  name="rand5_btn" class="btn btn-success" value="Enter">
</form>

 //Javascript
<script type="text/javascript"> 
            function sendForm(e){
                e.preventDefault();
            }

        </script>

4 个答案:

答案 0 :(得分:0)

尝试在按钮中添加localhost:15672而不是表单

答案 1 :(得分:0)

您可以在表单

中更改onsubmit而不是onclick

function sendForm(e) {
  e.preventDefault();
}
<form method="post" action="index.php" onsubmit="sendForm(event);"><!--changes-->
  <input type="text" class="form-control" id="code" name="rand5_code">
  <input type="submit" href="" name="rand5_btn" class="btn btn-success" value="Enter">
</form>

答案 2 :(得分:0)

将按钮type="submit"更改为按钮Type="button"和 使用jquery ajax

$("#btnid").click(function(){
    $.ajax({

    method: "POST",

    url: "some.php",

    data: { name: $('#code').val()}

    })

    .done(function( msg ) {

    alert( "Data Saved: " + msg );

    });
})

同时从表单

中删除action

答案 3 :(得分:0)

onsubmit="return false;"添加到表单中。在你js函数e中clickEvent不是SubmitEvent,submitEvent make page reload。

<!--HTML-->
    <form method="post" action="index.php" onsubmit="return false;" onclick = "sendForm(event);">            
       <input type="text" class="form-control" id="code" name="rand5_code">
        <input type="submit" href=""  name="rand5_btn" class="btn btn-success" value="Enter">
    </form>

     //Javascript
    <script type="text/javascript"> 
        function sendForm(e){
            e.preventDefault();
        }

    </script>