使用jQuery的AJAX请求不发布表单数据

时间:2022-11-24 13:30:49

I'm trying to create a search form that posts the results queried from a MySQL database and I'm having trouble. The query is running correctly but the information entered in my form field is not 'posting' into the php document and actually getting through

我正在尝试创建一个搜索表单,用于发布从MySQL数据库查询的结果,我遇到了麻烦。查询运行正常,但在我的表单字段中输入的信息不是“发布”到php文档中并实际通过

    <form name="IDsearchform" action="">
    <input class='required digits' type="text" value="" maxlength='8' minlength='8' name="term" id="search" />
    </form>


$(document).ready(function(){
    //show loading bar
    function showLoader(){
        $('.search-background').fadeIn(200);
    }
    //hide loading bar
    function hideLoader(){
        $('#sub_cont').fadeIn(1500);
        $('.search-background').fadeOut(200);
    };
    $('#search').keyup(function(e) {
      if(e.keyCode == 13) {
        showLoader();
        $('#sub_cont').fadeIn(1500);
        $("#content #sub_cont").load("<?php bloginfo('template_directory'); ?>/searchID.php", hideLoader());
      }
      });     
    $(".searchBtn").click(function(){   
        //show the loading bar
        showLoader();
        $('#sub_cont').fadeIn(1500);         
        $("#content #sub_cont").load("<?php bloginfo('template_directory'); ?>/searchID.php", hideLoader());
    });
});

2 个解决方案

#1


0  

You should include the extra parameter in your call to $.load():

您应该在调用$ .load()时包含额外参数:

$("#content #sub_cont").load("<?php bloginfo('template_directory'); ?>/searchID.php",
 {term:$(#search.value)}, hideLoader());

It's important to include the data, first of all. ;-) Second, you want to make sure that the data is an object so that jquery will do a POST instead of a GET.

首先包括数据非常重要。 ;-)其次,您要确保数据是一个对象,以便jquery将执行POST而不是GET。

Source

资源

#2


1  

What you need to do is fist serialize the form data and then send it across. Otherwise jquery does not send the form data. This is what you need to do -

您需要做的是先将表单数据序列化,然后将其发送出去。否则jquery不发送表单数据。这就是你需要做的 -

$("#content #sub_cont").load("<?php bloginfo('template_directory'); ?>/searchID.php",$("#IDsearchform").serialize(), hideLoader());

$(“#content #sub_cont”)。load(“<?php bloginfo('template_directory');?> / searchID.php”,$(“#IDsearchform”)。serialize(),hideLoader());

This way your form post data is automatically send my jQuery.

这样你的表单发布数据就会自动发送我的jQuery。

#1


0  

You should include the extra parameter in your call to $.load():

您应该在调用$ .load()时包含额外参数:

$("#content #sub_cont").load("<?php bloginfo('template_directory'); ?>/searchID.php",
 {term:$(#search.value)}, hideLoader());

It's important to include the data, first of all. ;-) Second, you want to make sure that the data is an object so that jquery will do a POST instead of a GET.

首先包括数据非常重要。 ;-)其次,您要确保数据是一个对象,以便jquery将执行POST而不是GET。

Source

资源

#2


1  

What you need to do is fist serialize the form data and then send it across. Otherwise jquery does not send the form data. This is what you need to do -

您需要做的是先将表单数据序列化,然后将其发送出去。否则jquery不发送表单数据。这就是你需要做的 -

$("#content #sub_cont").load("<?php bloginfo('template_directory'); ?>/searchID.php",$("#IDsearchform").serialize(), hideLoader());

$(“#content #sub_cont”)。load(“<?php bloginfo('template_directory');?> / searchID.php”,$(“#IDsearchform”)。serialize(),hideLoader());

This way your form post data is automatically send my jQuery.

这样你的表单发布数据就会自动发送我的jQuery。