March 6th, 2013, 03:23 AM
Jquery's mobile framework/phoneGap - dynamic content?
I am having trouble thinking of ways to serve dynamic content?
If you are familiar with these technologies, you will know that the pages have to be html and to use serverside you have to use jquery post data.
This all works for when i am logging user in. but how do i serve dynamic content so say i had a table in my database called orders,
once user logs in, I can show him all the orders list like this:
<a href="">Order 1</a>
<a href="">Order 2</a>
in a normal website the href would be something like: "orders.php?order_id=1234"
but I cant do that with Jquery/phonegap as they would probably open up a browser window (Not tested)
so i was thinking of doing something elaborate:
<a id="orderId" href="">Order 1</a>
<a id="orderId" href="">Order 2</a>
then using jquery detect which link they clicked on, get the ID attribute, and then i can:
1. send that to the server to get the relevant details
2. store it in the local storage, redirect user to another page orders.html and on page initialisation, use the local storage to get the data and do a post request..
March 6th, 2013, 12:42 PM
You don't have to POST data, you can issue a GET request with jQuery too.
I don't know specifically how Phonegap will handle the href attribute in A links; it's worth trying though, as it might do exactly what you need without any additional effort on your part.
If it doesn't, then the approach you're considering is the correct one, but I would not use the "id" attribute to hold your order ID values. Instead, use a custom attribute for it:
Then you can bind an event handler to ".order-link" that will retrieve the appropriate data using the orderid attribute.
<a orderid="5" class="order-link">Order 5</a>
As a more generic approach, you could just use jQuery to bind to the click event on all <a> tags so that when clicked they request their href URL over an xmlhttprequest instead of invoking the native behavior of Phonegap. That way you don't have to write as many distinct event handlers.
I don't understand this logic at all:
Why not just send them to orders.html first, show a loading icon initially, send the HTTP request to the server to get the order information, then hide the loading icon and update the page with the contents from the server.
March 6th, 2013, 03:24 PM
thanks for replying.
post/get, you still need to send data to the server right. & to do that, need an id or am I missing something?
re your q:
these were two choices i was saying could happen.so for ex. if you clicked on order 1, i could either send order id to server through ajax & get the data OR store the id then take them to next page etc...
if i send them to orders.html first, how would I get the order id the selected?