jQuery的Ajax的GET方法不传递变量 [英] Jquery Ajax GET method not passing variables

查看:280
本文介绍了jQuery的Ajax的GET方法不传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的网址工作正常:

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();

这篇关于jQuery的Ajax的GET方法不传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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