传入 url 的 jquery $.GET 参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5383222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:03:58  来源:igfitidea点击:

jquery $.GET parameters passing in the url

jqueryparametersget

提问by luca

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

这是使用 Jquery 发出 GET 请求的通用方法:

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

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

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

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

Is that possible? And anyhow wich is the cleanest solution to make an ajax call if I have all of the parameters I need urlencoded (Ex.rate me)

那可能吗?无论如何,如果我拥有需要 urlencoded 的所有参数,那么这是进行 ajax 调用的最干净的解决方案(Ex.rate me)

回答by Paramount

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

回答by Gate

$.get(

  url: url,    //your url eg. mypage.php

  data: data,   // Parameter you want to pass eg. {version:"5" , language : "php"}

  success: callback // function after success

);

follow the below link

按照下面的链接

http://api.jquery.com/jQuery.getJSON/

http://api.jquery.com/jQuery.getJSON/