游.程 2015-04-24 18:06 采纳率: 0%
浏览 52

javascript ajax jQuery

I m validating variables from html inputs in ajax javascript .

What i m trying to do for sure is when client Click the Submit button which it variable is var sub another div from html file should appear but after completing to fill the required fields.

But when i tried doing it i get no response means the html div that should appear

HTML

            <span id="formst">User name:<input type="text" name="username" id="user" onBlur="checkU();"/>
            <div id="staut"></div>
            <br /><br />
            Phone Number:<input type="tel" name="number" id="tel" value="+255" />
            <div id="stau"></div>
            <br /><br />
            <h3>Your Description</h3>
            <textarea rows="6" cols="22" id="textarea" ></textarea><br /><br />
            <input type="submit" value="submit" onClick ="payment();" id="sub"/>
            <div id="st"></div>
            </span>
        </form>


<div id="payment2">

            <ul id="adjustPay">
                <li id="tigo" onClick="Tigo();">Tigo Pesa</li>
                <li id="voda">Vodacom Mpesa</li>
                <li id="air">AirTel Money</li>
            </ul>
        </div>
    </div>

and ajax javascript Jquery code

    var ajax = ajaxObj("POST", "function.php");
    info.innerHTML = "Please wait ...";
    ajax.onreadystatechange = function(){
        if(ajaxReturn(ajax) == true){

    if(ajax.responseText != "please wait"){
        info.innerHTML = ajax.responseText;
        sb.style.display = "block";

        }else if(ajax.responseText = "please wait"){

    $(document).ready(function(){

        $("#form").show(function(){
            $("#form").slideUp(3840);
            $("#payment2").show();

        });
    });
}


        }
    }

    ajax.send("u="+u+"&n="+n+"&t="+t);

}

Problem is on else if(ajax.responseTex = "please wait")

please if there is any way of doing this just show me

  • 写回答

1条回答 默认 最新

  • weixin_33717117 2015-04-24 18:19
    关注

    You need something like this - you need to change #sb and data to reflect the actual element and the data returned

    $(function(){
      $("#form").on("submit",function(e) { // when submitted
        e.preventDefault(); // cancel the submission
        $("#info").html("Please wait ...");
        $.post(function.php",$("#form").serialize(),function(data) {
         if (data != "please wait"){
           $("#info").html(data);
           $("#sb).show();
         else {
          $("#form").show(function(){
            $("#form").slideUp(3840);
            $("#payment2").show();
         });
      });
    });
    
    评论

报告相同问题?