jQuery的Ajax的GET方法不传递变量变量、方法、jQuery、Ajax

2023-09-10 14:56:57 作者:与你同行

下面的网址工作正常:

index.php?page=search_result&maker=Any

我想进入这个网址的使用jQuery的Ajax功能的另一页。 这是我的Ajax调用:

I want to get into this URL from another page using Jquery Ajax function. Here is my Ajax call:

$(function(){

    $(".by_maker").on('click',function(){

        var c_maker = $(this).attr('href');

         $.ajax({
               type: "GET",
               datatype: "html",
               url: "index.php?page=search_result",
               data: "maker="+c_maker,
               success: function(response){
                       html(response);} 
           });
    });
});

我想获得'制造商'的价值从HREF中包含HTML:

I like to get the value of 'maker' from the href like below html:

<a class="by_maker" href="toyota">Toyota</a>

注:没有形式和输入元素。如果我点击链接丰田公司不会所需的URL!所以,我在做什么错了??? 任何帮助是AP preciated。提前致谢。

NB: there is not 'form' and 'input' elements. If I click on the Toyota link its not going to the desired URL!!! So, what am I doing wrong??? Any help is appreciated. Thanks in advance.

推荐答案

添加返回:FALSE; 到事件处理程序停止默认动作

add return:false; to the event handler to stop the default action.

$(".by_maker").on('click',function(){

    var c_maker = $(this).attr('href');

     $.ajax({
           type: "GET",
           datatype: "html",
           url: "index.php?page=search_result",
           data: "maker="+c_maker,
           success: function(response){
                   html(response);} 
       });
       return false;
});

另外,您也可以通过在事件的回调函数, preventDefault();

$(".by_maker").on('click',function(event){
    event.preventDefault();