jQuery的基于Ajax的搜索jQuery、Ajax

2023-09-10 21:11:31 作者:青春走了痘還在

我想用做搜索阿贾克斯jQuery的JS,对于我已经采取了这块的code从这里: -

I want to do the search using ajax jquery js, for that I have taken this piece of code from here:-

现在我有一些问题,我有这个JavaScript code: -

Now i have some issues, I have this Javascript code:-

<script language="JavaScript" type="text/javascript">
<!--
function searchuser(cv) {
    $("#SearchResult").html('<img src="loader.gif"/>').show();
    var url = "elements/search-user.php";
    $.post(url, {contentVar: cv} ,function(data) {
       $("#SearchResult").html(data).show();
    });
}
//-->
</script>

我的形式: -

My Form:-

<label>
        <input onClick="generatenew();" type="radio" name="search_option" value="code" id="search_option_0">
        Customer Code</label></td>
      <td><label>
        <input onClick="generatenew();" type="radio" name="search_option" value="company" id="search_option_1">
        Customer Company</label></td>
      <td><label>
        <input onClick="generatenew();" type="radio" name="search_option" value="name" id="search_option_2">
        Customer Name</label></td>
      <td><label>
        <input onClick="generatenew();" type="radio" name="search_option" value="email" id="search_option_3">
        Customer Email</label>

这是我的搜索文本框

<input type="text" name="searchuser_text" id="newInput" size="25" maxlength="25" class="inputbox MarginTop10">

这是我的搜索按钮

<input onclick="javascript:searchuser('con1');" class="Button" name="search_user_submit" type="button" value="Search">

这是我的显示面积: -

This is my Display Area :-

<div id="SearchResult">My default content for this page element when the page initially loads</div>

现在我想知道在点击按钮,我送一个数据,即 con 1的。我想两个数据发送到 searchuser功能,其中一个选择的选项按钮值,另外一个是在文本框中的文本。无论是数据发送到功能,我将如何获得数据的功能后?我是否需要更改函数searchuser(CV)函数searchuser(CV,cvtwo)

Now i want to know on click of button i am sending a data i.e. con1. I want to send two data to the searchuser function, one the selected option button value and the another one is the text in the textbox. After sending both the data to the function how will i get the data in the function? Do i need to change the function searchuser(cv) to function searchuser(cv, cvtwo).

此外,而 $职位(URL,{contentVar:CV},功能(数据)是只发送一个数据到PHP文件,我怎么能同时发送即数据 CV cvtwo 的PHP文件?

Also while the $.post(url, {contentVar: cv} ,function(data) is sending only one data to the php file, how can i send both the data i.e. cv and cvtwo to the php file?

推荐答案

首先,你可以修改搜索功能,这样的事情

First of all you can modify the search function to something like this

$("input[name='search_user_submit']").click(function(){
var cv = $('#newInput').val();
var cvtwo = //similar to above
var data = 'cv='+ cv + '&cvtwo='+cvtwo; // sending two variables
$("#myDiv").html('<img src="loader.gif"/>').show();
    var url = "elements/search-user.php";
    $.post(url, {contentVar: data} ,function(data) {
       $("#SearchResult").html(data).show();
    });

});