2014-01-28 15:32
浏览 35


thanks for reading my problem and sorry if my english is not perfect.

So, my problem is when i send a form via ajax with the method post, my page bug when reloading. After some test, i found that if i use the method get, everything works fine. I don't get it. Also, if i comment the select part, it works even with post.

Here is my code: The ajax function:

    function showDispo(){

    function validate(form) {

                url: "updateDispo.php"
                , data: $(form).serialize()
                , datatype: 'json'
                , type: 'post'
                , error: function(error, errmsg){
                    alert(errmsg + ' :=: ' + error.responseText );
                , success: function(Data) {

and my html code:

<form method="get" id="frmUpdateTaux">
        <table border="0" cellspacing="0" cellpadding="2">

                <td align="left">
                    <label class="lbl" id="lblMois" name="lblMois" for="lstMois">Mois :</label>
                <td align="left">
                    <select id="lstMois" name="lstMois" size="1">
                        <option value="1">Janvier</option>
                        <option value="2">Février</option>
                        <option value="3">Mars</option>


                <td align="left"  colspan="2">
                <input type="button" id="btnGenerate" name="btnGenerate" value="Mettre à jour" onclick="showDispo()">


require_once("BD.php"); $month= $_POST["lstMois"]; /*query */ $insertNewIndispo ='...' //execution of the query 

//QUERY INSERT $insertNewIndispo ='...'

$exec = BD::run($insertNewIndispo, BD::QUERY_INSERT, false, false);

FYI: I want to reload the page to display the results of a query run in this page and new values are inserted in the DB table by UpdateDispo.php

Do you have an idea where the problem comes from?


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongpu9481 2014-01-28 16:29

    perhaps the problem you have is the following:

    <form method="get" id="frmUpdateTaux">

    How can you get $_POST if you are sending $_GET?

    If you want to use ajax, then try:

    <form onsubmit="return false;" id="frmUpdateTaux">

    Then you can use your ajax code to catch the variables you are sending.

    Btw: For ajax I use the following code to catch form data:

        // First declare your variables by their ID.
        var lstMois = document.getElementById('lstMois').value;
        var ajax = ajaxObj("POST", "put here your filename(can be the same as the one you are currently browsing)");
        ajax.onreadystatechange = function() {
            if(ajaxReturn(ajax) == true) {
                if(ajax.responseText == "success"){
                    // Do something.
                    } else {
                    // Something went wrong, alert them.
                    alert("Oops! Something went wrong. Please try again.")

    Then you should have php code in the page you are referring to, which will have something like this:

    $lstMois = $_POST['lstMois'];
    // Do whatever you want with it.
    // If everything went well:
    echo "succes";

    The ajax code will see php has sent 'succes' to it, and will do whatever you say in

    if(ajax.responseText == "success"){

    PS. Sorry for my English, I'm not a native speaker.

    点赞 打赏 评论

相关推荐 更多相似问题