传入 URL 的 jQuery $.GET 参数 [英] jQuery $.GET parameters passing in the URL

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

问题描述

这是一种使用 jQuery 发出 GET 请求的通用方法:

this is a general-purpose way to make GET requests with jQuery:

var loadUrl="mypage.php";
$("#get").click(function(){   
    $("#result").html(ajax_load);   
    $.get(   
        loadUrl,   
        {language: "php", version: 5},   
        function(responseText){   
            $("#result").html(responseText);   
        },   
        "html"  
    );   
});  

我想知道是否可以直接在 URL 中传递参数(Ex.language 和 version)(在对它们进行 urlencoding 之后):

I was wondering if I could pass parameters (Ex.language and version) directly in the URL(after urlencoding them):

var loadUrl="mypage.php?language=php&version=5";
$("#get").click(function(){   
    $("#result").html(ajax_load);   
    $.get(   
        loadUrl,      
        function(responseText){   
            $("#result").html(responseText);   
        },   
        "html"  
    );   
});  

这可能吗?无论如何,如果我拥有所有需要 urlencoded 的参数(例如,<a href="mypage.php?language=php&version=5>rate我)

Is that possible? And anyhow which is the cleanest solution to make an ajax call if I have all of the parameters I need urlencoded (Ex.<a href="mypage.php?language=php&version=5">rate me</a>)

推荐答案

是的,但你也可以这样做.

Yes that is possible but you can also do it this way.

$.get(
   "mypage.php", 
   { version: "5", language: "php" }, // put your parameters here
   function(responseText){
      console.log(responseText);
   },
   'html'
);

这篇关于传入 URL 的 jQuery $.GET 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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