Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing dynamic data JQueryMobile
    text
    copied!<p>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.</p> <ul> <li>I'm creating a multipage jquery template</li> <li>On the first page it show a list of items with a dynamic link from a JSON request.</li> <li>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: <strong>test3.html#blog?blog_id=10</strong></li> <li>I found a script to send the <code>blog_id</code> number to a JSON request and that is kinda working. I need to do a hard refresh to show the content.</li> </ul> <p>My first code (works):</p> <pre><code>&lt;script type="text/javascript"&gt; $.ajax({ url: 'test.cfc?method=books&amp;ReturnFormat=json', dataType: 'json', success: function(response) { var data = response.DATA; var str = '&lt;ul&gt;'; for (var I = 0; I &lt; data.length; I++) { str += '&lt;li&gt;&lt;a href="#blog?blog_id=' + data[I][0] + '"data-transition="slide"&gt;' + I + data[I][1] + '&lt;/a&gt;&lt;/li&gt;'; } str += '&lt;/ul&gt;'; $('#output').html(str); }, error: function(ErrorMsg) { console.log('Error'); } }); &lt;/script&gt; </code></pre> <p>And then the second code (which is not working); First part trying to filter the <code>blog_id</code> 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.</p> <pre><code>&lt;script type="text/javascript"&gt; function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&amp;'); for(var i = 0; i &lt; 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&amp;ReturnFormat=json&amp;blog_id='+blog_id, type: 'GET', dataType: 'json', success: function(response) { var data = response.DATA; for (var I = 0; I &lt; data.length; I++) { str = '&lt;h1&gt;' + data[I][0] + '&lt;/h1&gt;' + data[I][1] ; } $('#outputblog').html(str); }, error: function(ErrorMsg) { console.log('Error'); } }); &lt;/script&gt; </code></pre> <p>Can please someone help to approve my code or give some suggestions? Thanks!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload