簡體   English   中英

javascript按鈕ajax和php

[英]javascript button ajax and php

我有一個小問題,我想我覺得這聽起來很愚蠢。 我實際上有這個代碼

<script type="text/javascript">
$(document).ready(function(){

var email_value = prompt('Please enter your email address');
if(email_value !== null){
//post the field with ajax
$.ajax({
    url: '="/new/cfolder.php',
    type: 'POST',
    dataType: 'text',
    data: {data : email_value},
    success: function(response){ 
     //do anything with the response
      console.log(response);
    }       
}); 
}

});
</script>

我想將它鏈接到我執行此操作的按鈕

<form action="/new/cfolder.php" method="post">
    </font><input type="submit" value="Create Vdisk" class="myButton6" onClick="function()"> 
<br></form>

實際上可以這樣做嗎? 謝謝你的回答。

 <script type="text/javascript">
  $(document).ready(function(){
    $(document).on('click', '.myButton6', function(){
      var email_value = prompt('Please enter your email address');
      //post the field with ajax
      if(email_value.length > 0){
        $.ajax({
            url: '/new/cfolder.php',
            type: 'POST',
            dataType: 'text',
            data: {data : email_value},
            success: function(response){ 

              alert(response);
            }       
        }); 
      }
    )};
  }); 
</script>

試試這種方式

// this is the id of the form
$("#idForm").submit(function() {

var url = "path/to/your/script.php"; // the script where you handle the form input.

$.ajax({
       type: "POST",
       url: '="/new/cfolder.php',
       data: $("#idForm").serialize(), // serializes the form's elements.
       success: function(data)
       {
           alert(data); // show response from the php script.
       }
     });

return false; // avoid to execute the actual submit of the form.
});

給你的表格一個id

<form id="idForm" action="/Same/path/as/your/ajax/" method="post">
</font><input type="submit" value="Create Vdisk" class="myButton6" onClick="function()"> 
<br></form>
Yes of course you can do this . Like  this code and you will have to include jquery1.9.0.js or above.


 <script type="text/javascript">
    $(document).ready(function(){
    $("#myButton6").click(fuction(){
    var email_value = prompt('Please enter your email address');
    if(email_value !== null){
    //post the field with ajax
    $.ajax({
        url: '/new/cfolder.php',
        type: 'POST',
        dataType: 'text',
        data: {data : email_value},
        success: function(response){ 
         //do anything with the response
          console.log(response);
        }       
    }); 
    }

    });

    });
    </script>
    I would like to link it to my button which does this


 </font><input type="submit" value="Create Vdisk" class="myButton6" id="myButton6"> 
    <br>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM