Newbie question.
Found that most of tutorials in the Internet focused how to pass parameters by GET / POST. Just some of them pointed to retrieval data and mostly by using PHP (jQuery docs) / ASP.NET etc.
How to retrieve AJAX posted data using pure JavaScript?
Exactly:
Post:
function detailOperator(_recordId, _title) {
$.mobile.changePage('#operator-view',
{ dataUrl: '?ID=' + _recordId + '&title=' + _title});
}
Post changing page successfully.
How to retrieve ID and title in operator-view page?
POST data cannot be obtained by client side scripts, unless the server side script handing the POST request sends it back to the client with the response. In short, there is no built-in way of doing this.
However, your server side script can choose to pass the POST data back to the client via cookies or hidden variables and then your client side JavaScript can access the values therein.
POST values are not accessible client side. GET values can be accessed via
window.location.search
What finally I've got (commented Jim' idea):
Pass parameters:
function detailOperator(_recordId) {
$.mobile.changePage('#operator-view', { dataUrl: '?ID=' + _recordId });
// Below not working (no errors) - maybe this sample working for external pages?
//$.mobile.changePage('#operator-view', { dataUrl : '?ID=' + _recordId, data : { 'ID' : _recordId }, reloadPage : true, changeHash : true });
}
so, here the same as it was.
Retrieve parameters:
// Below not working (no errors) because of empty "url"
/*
var parameters = $(this).data("url").split("?")[1];;
var _recordId = parameters.replace('ID=', '');
*/
var parameters = location.hash.substring(2).split("&");
var _recordId = parameters[0].replace('ID=', '');
Thanks a lot for patience!