Ajax made Simple Part 7: Use JSONP to get a stock quote

Working with Ajax, we have run into the Same Origin Policy over and over again. In this post, we’ll show you another way to get around it.

The Same Origin Policy restricts you from loading files from a server not your own. There is an exception: JavaScript (.js) files are allowed.

There are sites on the web where you can request information and have it passed back in JSONP format. The “P” stands for padding: JSONP is JSON with padding. The results are returned as a function call, with the results as parameters. That function can then be called in your program.

Continue reading “Ajax made Simple Part 7: Use JSONP to get a stock quote”

Programming Contest Announced!

Our second NS Basic/App Studio Programming Contest starts today. We’re looking forward to cool entries which take advantage of the capabilities of devices and App Studio.

We have two categories: Web App and App Store. Web Apps are installed from a browser, while App Store apps are distributed through the Apple, Google, BlackBerry or other store. All registered NS Basic users are welcome to participate in the contest. Prizes are $100 USD in each category.
contest

You may enter more than one program. Judging will be by NS Basic’s experts. All judging is arbitrary and final. We will be looking for quality, performance, ease of use, sophistication and overall coolness. Apps can be whatever you like: enterprise, business, commercial, education, games or even something whimsical.

All programs must be written using NS Basic/App Studio. Entries may be commercial, shareware or freeware, and for iPhone, iPad, Android, BlackBerry or multiple platforms. Please indicate with your entry whether we can share your program or screenshots with the public.

Send your questions and entries to support@nsbasic.com.

The deadline for entries is Monday, April 23, 2012 at 12:00 midnite EST.

NS Basic/App Studio 2.1 Released!

We happy to announce that Version 2.1 is ready!

The list of enhancements and fixes is extensive. Major new features include:

  • Support for Libraries: These are easy to add libraries for your app. Libraries include AddToHomeScreen, Encryption and Sencha Touch.
  • AutoComplete: Now, when you type the period after an object, a list of members of that object will display.
  • The Open and Samples dialogs are now resizable.
  • Lots of smaller improvements and fixes. Check out the complete history.

The URL is the same as before. If you don’t have it anymore, be patient: we are sending an email to all registered users with the information.

The team here has been working hard on this new release. Great job, guys!

Ajax Made Simple Part 6: Where to put your PHP file

For development, put the PHP files for your project right in your project folder. You can then use any text editor that you have installed on your system to edit them.

Next, add the file names to the manifest in Project Properties. When you do a Full Deploy, they will be copied to the server with the rest of your project.

The result is that your PHP files will be placed on the server, in the same folder as your app. Your app can call a PHP script by just giving the file name – no path name will be needed.

Ajax made Simple Part 5: Asynchronous Calls

In our last Ajax discussion, we discovered that it could take half a second for an Ajax call to complete (actually, due to network latency, it could even be a lot more than that.) How do we do Ajax calls and not make our app look slow?

Easy. We send the Ajax message off, then go do other stuff. When the response comes back, we respond to it. This is called Asynchronous operation.

We do this by adding the name of the function to be called on completion as the 4th parameter of our Ajax call:

req=Ajax("ajax.php/?myText=" + txtSend.value, "", "", done)

Continue reading “Ajax made Simple Part 5: Asynchronous Calls”

Ajax made Simple Part 4: How fast is it?

If your app is going to communicate with your server while it is running, you’ve probably wondered how much your app will slow down when it has to wait for the server.

In this blog post, we’re going to make a program to test this. We’ll construct a little program which sends data to the server as many times as it can. The server will record the information in a log file. Here is what our app will do:

  Do Until SysInfo(10) > limit
    req=Ajax("ajaxLog.php/?myText=" + Now)
    counter=counter+1
  Loop

Continue reading “Ajax made Simple Part 4: How fast is it?”

Using Custom Fonts

It turns out that it is quite easy to use custom fonts in an App Studio project. This is useful if you need a specialized font (not one of the official 13) or want to give your app a unique look. Here’s a step by step guide:

  1. Put the font file in your project directory. It should be in .ttf format.
  2. Drag it from there into your Project Explorer
  3. Add this line to extraheaders in Project CSS:
    @font-face {font-family: sansation; src: url('Sansation_Light.ttf');}
    

    4. Set the fontfamily of your controls to the name of your font face. In this case, it would be ‘sansation’.

    That’s it!

    (See the CustomFont sample in folder 2 to try it out.)

NS Basic/App Studio 2.0.1 Released!

We have just released NS Basic/App Studio 2.0.1. The new release has some minor new features and a number of bug fixes. The URL is the same as before.

Here is the list:

2.0.1

  1. IDE: Add new default screen sizes on New Project.
  2. IDE: Added landscape form factors to New Project.
  3. Code Window: Highlight ‘Step’ keyword.
  4. Code Window: Try and Catch no longer are flagged as syntax errors.
  5. Docs: Handbook and Language Reference updated.
  6. Language: TimeSerial() now carries result if values are large.
  7. Runtime: jQuery Mobile updated to version 1.0.1.
  8. Samples: AddToNumbers: add a reset button.
  9. Samples: jQM List: Show text of selected item.
  10. Samples: new jQM ListWithScrolling sample.
  11. Samples: new SQLSample3.
  12. Samples: New Transitions sample – work in progress.
  13. Samples: Open Sample screen is resizable – more improvements coming.
  14. Toolbox: Add setIndex() function to Select control.
  15. Toolbox: Fix default on ‘hidden’ property.
  16. ToolBox: jQM FooterBar on new form fixed.
  17. Toolbox: native menu is now the default.
  18. Translator: CDate(“hh:yy:ss”) fixed.
  19. Translator: Replace(a, “&”, “&”) fixed.
  20. Translator: Replace(a,”&”, “&”) fixed.
  21. Translator: text in comments no longer affects function defs.

Changing the splash screen at runtime

If you save an app to the home screen on an iOS device, you can display a nice splash screen when it launches. But what if the user switches to a different app, then returns to yours? It will have quit and needs to launch again.

You can save the current state to localStorage and write some code to go right back to where you were: but the splash screen will show again. You can suppress it by adding these lines to your restart code:

Dim headerChildren=document.getElementsByTagName("head")[0].children
Dim i=0
Do While i<UBound(headerChildren) And headerChildren[i].rel<>"apple-touch-startup-image"
  i=i+1
Loop
document.getElementsByTagName("head")[0].removeChild(headerChildren[i])

This code finds the splash screen in the header of the page and removes it.

Tip: Embedding NS Basic Apps in web pages

You might be wondering how I managed to embed an NS Basic app in the following post about jQuery Mobile.

Easy – here is the HTML:

<iframe src="http://www.nsbasic.com/KitchenSink" width=320 height=480>
</iframe>

You can now run the app as normal. Great way to do demos!