English 中文(简体)
简单的jquery和php问题
原标题:Simple jquery and php problem

是否有任何人知道为什么没有工作? 希望得到任何帮助。

这是超文本

Enter Code:<br/><input type="text" name="code" id="code"/><br/> 
<input type="button" id="confirm" value="Confirm" onClick="confirm()"/> 

这就是PHP(基本上获得用户投入的价值,如果与变量相同的话)

$code = $_POST["code"]; 
$a = 105678; 
if($code==$a){ 
  echo "sucess"; 
} else { 
  echo "nosucces"; 
} 

Java:(简单地用麻ja或无ces的na)

function confirm () { 
  $.post(
    "confirm.php",
    {code:$(this).val() },
    function(data) { 
      if(data== sucess ) { 
        alert("yay"); 
      } else { 
        alert("nay");
      } 
    }
  ); 
}

basically on all occasions the ouput is nay on further debugging i tried an elseif statement on the javascript asking if data is equal to nosucces but it didn t even alert anything, meaning it s not getting the data from the php

问题回答
    $(document).ready(function() {
    $( #confirm ).click(function() {
        $.post("",{code:$( #code ).val() } ,function(data)
        {
            if(data== sucess )
            {
                alert("yay");
            }
            else
            {alert("nay");}
        });
    });
});

结尾处的方括号,以便可以理解,你正在要求一种功能,也不要将<条码>confirm/code>作为功能名称、其原有的SJ功能、使用<条码>my_confirm。

onClick="my_confirm()"

另外,$(this.val()在你的案件中赢得了t work$(#code ).val().

$(document).ready(function() {
    $( #confirm ).click(function() {
       $.ajax({
         url: "confirm.php",
         type: "POST",
         data: "code="+$( input[name="code"] ).val(),
         dataType: "text",
         async:false,
         success: function(msg){
           if(msg== sucess ){
             alert( yay );
           }else{
             alert( nay );
           }
         }
       });
    });
});




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...