0

I've been reading a tutorial called Adding SQL Database support to your iPhone App(I use PhoneGap because I won't get on Objective-C), I've done that all, but now when I tried to display the result(celebsDataHandler) like this it shows nothing:

<script type="text/javascript" charset="utf-8" src="db.js"></script>
<script type="text/javascript" charset="utf-8">
  document.write(celebsDataHandler);
</script>

What should I do to correct this problem?

2 Answers 2

1

celebsDataHandler appears to be a function, based on what the tutorial says. You can't document.write a function.

Have you tried using a more versatile command like console.log to see what the value of celebsDataHandler is?

Or, you may wish to change the last line of the function from

  alert(html);

to

  return html;
Sign up to request clarification or add additional context in comments.

Comments

0

First, you need to have some part of your document set up to handle showing the celebrities, for this example. Make sure you have a DOM element in your HTML page that has an ID that you can reference, for example:

<div id="myCelebs"></div>

Next, change the last line of the celebsDataHandler function to:

document.getElementById('myCelebs').innerHTML = html;

Finally, in your inline script, change your document.write call to:

loadCelebs();

To recap what is going on:

  • The loadCelebs function contains the SQLite code that queries the database and retrieves your data. It references a callback function (in this case named celebsDataHandler) that is invoked once the data is ready to be parsed.
  • The celebsDataHandler callback function iterates over results and compiles celebrity data into HTML - which it then injects into the "myCelebs" DOM element.

Hope that helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.