用jQuery的Get函数发送值 [英] Sending values with jQuery's Get function

查看:67
本文介绍了用jQuery的Get函数发送值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一些东西来检查我的数据库以检查重复的错误。这是一种形式,我有以下功能使用jQuery.get检查重复值。

 函数makeAjaxRequest()
{
$(label#bad_error)。hide();
$(label#good_error)。hide();
$(label#checkingdb_error)。show();
$ b $ .get(url,{sheetnum:'$(input#sheetnum)。val()'},verifyDb);


函数verifyDb(响应)
{
if(response == 1)
{
$(label#checkingdb_error )。隐藏();
$(label#bad_error)。show();


else
{
$(label#checkingdb_error)。hide();
$(label#good_error)。show();


$ / code $ / pre

我有这样做在文本字段的Blur 。我的php文件如下:

 <? 

$ sheetnum = $ _GET ['sheetnum'];

if($ sheetnum ==1234){
echo1;
}

?>

现在我用1234而不是mysql字符串来测试javascript的那一面这是工作。

当我在文本框中键入1234时,它返回没有错误(good_error标签)。我在.get字符串中输入了错误的值吗?请帮助。

解决方案

我相信

  $。get(url,{sheetnum:'$(input#sheetnum)。val()'},verifyDb); 

应该是

  $。get(url,{sheetnum:$(input#sheetnum).val()},verifyDb); 


I am currently coding something to check my database to check for duplicate errors. It is a form and I am having the following function check for duplicate values using jQuery.get.

function makeAjaxRequest()
{
   $("label#bad_error").hide();
   $("label#good_error").hide();
   $("label#checkingdb_error").show();

   $.get(url,{sheetnum: '$("input#sheetnum").val()'},verifyDb);
}

function verifyDb(response)
{
    if (response==1)
    {
   $("label#checkingdb_error").hide();
   $("label#bad_error").show();
    }

    else
    {
   $("label#checkingdb_error").hide();
   $("label#good_error").show();
    }
}

I am having it do this onBlur of a text field. My php file is as follows:

<?

$sheetnum = $_GET['sheetnum'];

if($sheetnum == "1234"){
echo "1";
}

?>

I used "1234" instead of the mysql string for now, just to test that the javascript side of it is working.

When I type 1234 in the text box it returns that there are no errors (the good_error label). Am I putting the value wrong in the .get string? Please help.

解决方案

I believe

$.get(url,{sheetnum: '$("input#sheetnum").val()'},verifyDb);

should be

$.get(url,{sheetnum: $("input#sheetnum").val()},verifyDb);

这篇关于用jQuery的Get函数发送值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆