Ok I really need some help with this thing I'm testing. I'm trying to create a test phonegap app with JqueryMobile and I have the following question.
- I'm creating a multipage jquery template
- On the first page it show a list of items with a dynamic link from a JSON request.
- So far no problems. The problem starts when I click on a link. Now I manage to pass the URL variables with a script jquery.mobile.router.js. So the url is something like: test3.html#blog?blog_id=10
- I found a script to send the
blog_id
number to a JSON request and that is kinda working. I need to do a hard refresh to show the content.
My first code (works):
<script type="text/javascript">
$.ajax({
url: 'test.cfc?method=books&ReturnFormat=json',
dataType: 'json',
success: function(response) {
var data = response.DATA;
var str = '<ul>';
for (var I = 0; I < data.length; I++) {
str += '<li><a href="#blog?blog_id=' + data[I][0] + '"data-transition="slide">' + I + data[I][1] + '</a></li>';
}
str += '</ul>';
$('#output').html(str);
},
error: function(ErrorMsg) {
console.log('Error');
}
});
</script>
And then the second code (which is not working); First part trying to filter the blog_id
number which is passed in the URL. The alert is to check if the correct value is pasted. Second part should load the text of the blog, but is not really working.
<script type="text/javascript">
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
var blog_id = getUrlVars()["blog_id"];
alert(blog_id)
$.ajax({
url: 'test.cfc?method=blog&ReturnFormat=json&blog_id='+blog_id,
type: 'GET',
dataType: 'json',
success: function(response) {
var data = response.DATA;
for (var I = 0; I < data.length; I++) {
str = '<h1>' + data[I][0] + '</h1>' + data[I][1] ;
}
$('#outputblog').html(str);
},
error: function(ErrorMsg) {
console.log('Error');
}
});
</script>
Can please someone help to approve my code or give some suggestions? Thanks!!