jquery $ .GET参数在URL中传递 [英] jquery $.GET parameters passing in the url
本文介绍了jquery $ .GET参数在URL中传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个通用的方式来使用Jquery进行GET请求:
var loadUrl =mypage.php;
$(#get)。click(function(){
$(#result)。html(ajax_load);
$ .get(
loadUrl,
{语言:php,版本:5},
函数(responseText){
$(#result)。html(responseText);
},
html
);
});
我想知道是否可以直接在Url中传递参数(Ex.language和version) urlencoding):
var loadUrl =mypage.php?language = php& version = 5;
$(#get)。click(function(){
$(#result)。html(ajax_load);
$ .get(
loadUrl,
函数(responseText){
$(#result)。html(responseText);
},
html
);
}) ;
这可能吗?无论如何,如果我拥有所有需要urlencoded的参数(Ex.rate me),那么最简洁的解决方案就是做出ajax调用。 解决方案
是的,但您也可以这样做。
$。get(
mypage .php,
{version:5,language:php},//将参数放在这里
function(responseText){
console.log(responseText);
},
'html'
);
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"
);
});
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"
);
});
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)
解决方案
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'
);
这篇关于jquery $ .GET参数在URL中传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文