I want to pass 4 names using jQuery from one page to another page using jQuery in winRT app. done using one parameter. How to pass multiple parameters and retrieve in 2nd page?
Coding for one parameter.
default.html
:
<html>
<head>
<script>
$(document).ready(function () {
$(function () {
$('#navigate12').click(function () {
var te = $("#text1").val();
var tea = $("#text2").val();
window.location.href = "/page.html?cal=" + te;
});
});});
</script>
</head>
<body>
<button id="navigate12">navigate</button>
<input id="text1" type="text"/>
<input id="text2" type="text"/>
<input id="text3" type="text"/>
<input id="text4" type="text"/>
</body>
</html>
page.html
<html>
<head>
<script src="/js/jquery-1.9.1.js"></script>
<script>
$(document).ready(function () {
function qs() {
var qsparam = new Array();
var query = window.location.search.substring(1);
var parms = query.split('&');
for (var i = 0; i < parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0)
{
var key = parms[i].substring(0, pos);
var val = parms[i].substring(pos + 1);
qsparam[key] = val;
}
}
var msg = new Windows.UI.Popups.MessageDialog(val);
msg.showAsync();
}
var splitstr = qs();
});
</script>
<title>
</title>
</head>
<body>
</body>
</html>
You can pass GET parameters to a page using "?param=foo" for the first parameter. Additional parameters are included with "&" instead of "?".
Since you are passing GET parameters, you can put them all in the URL and read them in your target page. Alternatively, you can use POST parameters instead.
Here's a reference on GET vs PUT parameters:
http://www.w3schools.com/tags/ref_httpmethods.asp
If you are passing all parameters as GET, you can expand this bit:
var te = $("#text1").val();
var tea = $("#text2").val();
window.location.href = "/page.html?cal=" + te;
to something like this:
var te = $("#text1").val();
var text2 = $("#text2").val();
var text3 = $("#text3").val();
var text4 = $("#text4").val();
window.location.href = "/page.html?cal=" + te + "&text2=" + text2 + "&text3=" + text3 + "&text4=" + text4;
As for obtaining the parameters in the other page: I am assuming that you want to obtain the GET parameters in the other page via jQuery, since your target page is plain HTML. If this is the case, check this question