generate a dynamical html - iphone

How can i generate a dynamiccal html code in iphone like below:
NSString sHtml = #"<html><form name= \"PIOform\" >\
<input type=\"text\" name=\"txtUserName\" >\
<input type=\"text\" name=\"txtPassWord\" >\
</form>\
<input type=\"button\" onclick=\"goCallLogin(PIOform)\" >
</html>";
Yes, I want to create an UI iphone application with feature like a client HTML form to call a javascript method in any server:
When i click a button in iphone. It will call goCallLogin(PIOform) method in JS at address:
http;//www.myserver.com/login.js
How can i do?
Thank you

This seems like something better suited for an iPhone web app than a native app. Maybe you should look into doing that instead? There is no need to create HTML like this with a native app. If you want to send values to a remote server from a native app, take a look at writing a web service and accessing it from the iPhone. You could use REST or XML-RPC to activate the goCallLogin method that you were referring to.
Also, you cannot just call a javascript through a web browser and expect it to work. Javascript is a client-side technology. You need to look into writing your web service with a server-side language/framework such as PHP, Ruby on Rails, ASP.NET, etc.

Related

hello.js not in AngularJS web app not working on iPhones and Blackberry Z10s

I have a login system that works for most people (on Chrome, Android devices, IE8, Firefox, etc), but it seems not to work for people with Z10s or iPhone 5s. I don't have access to these devices so it's difficult to test, so I wanted to ask whether I was setting up everything properly.
It's an AngularJS app, using hello.js for OAuth, and bootstrap-social and font-awesome for the sign in buttons.
To insert hello into Angular, in app.js I include:
var app = angular
.module('myapp', [
'ui.bootstrap',
'ui.router',
'hello',
])
...
.run([..., 'hello', ..., function(..., hello, ...) {
...
hello.init(...);
...
}]);
...
var helloApp = angular.module('hello', []);
helloApp.factory('hello', function() {
return window.hello; // Assumes hello has been loaded
});
Then, in my loginCtrl, I inject it with
angular.module('myapp').controller('loginCtrl', [..., 'hello', ...,
function(..., hello, $location, ...) {
...
$scope.doLogin = function(network) {
console.log('Calling hello ' + network);
hello.login(network);
};
...
}]);
And in my view, I have
<button id="facebookLogin" class="btn btn-social btn-facebook" ng-click="doLogin('facebook')">
<span class="fa fa-facebook pull-left"></span> <span>Sign in with Facebook</span>
</button>
<button id="googleLogin" class="btn btn-social btn-google-plus" ng-click="doLogin('google')">
<span class="fa fa-google-plus pull-left"></span> <span>Sign in with Google</span>
</button>
Yesterday I was using onclick="hello.login('facebook')", and I suspected that was breaking on certain devices because I shouldn't be using onclick and hello wasn't in scope, so that's why I changed it to ngClick and calling a function in scope. The specific effect of onclick on the users who had errors was to redirect the user to the default/catch-all route without accessing the server at all (I listen for hello events and call the server, so this suggests it wasn't calling hello at all.)
But still, I ask the people who are having issues to re-try (after refreshing obviously), and now they say the button simply does nothing.
Other buttons on the site work. In fact, to get to this page, they use a <button> that uses ui-router to get to this page.
I'm going to continue to search, but I just wanted to ask if I seemed to be hooking hello.js into AngularJS properly, and not making any other beginner mistakes.
I believe the problem is that iPhones and Z10s were blocking hello.js's popup OAuth authentication, but I couldn't just switch it to use page.
When I tried, Facebook returns me to my redirect_url with the fragment
#access_token=....&expires_in=4264&state={%22client_id%22%3A%22164986300332415%22%2C%22network%22%3A%22facebook%22%2C%22display%22%3A%22page%22%2C%22callback%22%3A%22_hellojs_3ojn1yy8%22%2C%22state%22%3A%22%22%2C%22oauth_proxy%22%3A%22https%3A%2F%2Fauth-server.herokuapp.com%2Fproxy%22%2C%22scope%22%3A%22basic%22%2C%22oauth%22%3A{%22version%22%3A2%2C%22auth%22%3A%22https%3A%2F%2Fwww.facebook.com%2Fdialog%2Foauth%2F%22}}
it's ugly, but the point is it starts with a hash tag. So, while hello.js can normally read this, it couldn't in this case because Angular would mangle the address immediately. I'm not sure if this is because I specify to use hash-bangs instead of hash's, but it was.
And I couldn't send this to a PHP script or anything because the fragment after the hashtag would never make it to the PHP script.
So, my solution was to point the redirect_url at an independent page that has hello.js on it, but no Angular. It saves stuff to window.sessionStorage and redirects the user back to the login page, where hello.js passes the user through.
I'm not very confident in this ugly approach yet, so I put a browser sniffer to only do it for iPhones (and use popup for everyone else), I may remove this check in the future (because it's sketchy)
#matt it uses localstorage, not sessionstorage.
Use popup for all, and define a redirect_uri page with just hello.js In it. I dont know why you might think thats sounds wrong. All the demos do it this way. It also gives you a chance to display a nifty loading screen.
Sorry about the ugly fragment. It communcates a lot of state parameters which is used for the oauth proxy... most endpoints like facebook dont need it, so I might refactor that to make it a little less daunting.

GWT calling java from JS doesn't work with Iframe

I can run Java from JavaScript normally in a GWT application but when I run it in an iframe it doesn't work.
HTML
<input type="button" onclick="doIT()" value="Do"
class="fbbotton" style="margin-left: 20px" />
Java
$wnd.doIT = #com.application.client.application::saad();
static void saad()
{
GWT.log("saad");
}
What could be the problem?
If both pages are returned from different servers you need to take a look at the same origin policy (in short it is not possible).
If both sites are served from the same server (hostname and port) this should work, but you need to call the function properly.
If your iframe is a child of the page that your javascript is in you need to call: `
parent.doIT();

How to call SOAP service from Phonegap (iPhone app)

I am trying to call a SOAP service using this SOAP client but it is not working for me. Please help me. How can I send and receive XML SOAP with Phonegap?
Phonegap is HTML/JS/CSS commonly communicating via XHR/Ajax. It's better to use jQuery Ajax functions. You can get the details here.
Eg:
Posting-XML-SOAP-Requests
AJAX-Requests-Between-jQuery
Simple jQuery client to call a SOAP web service
If you find any cross-domain issues (or working in a browser and not working with simulator/device), please refer to the below steps.
Go to the Resources folder, you can see a file named Cordova.plist. Click on that and you can see the Root elements. Right click on the Root, add a row, set the key as ExternalHosts with type Array.
Expand the item, and add an item as item0. Give it type string and enter the value as '*'.
Don't forget to save the Cordova.plist after changes (just use cmd+s).

How to add a contact form to a static web site?

I have a mostly "static" web site with no server-side code and just a little JavaScript. Now I would like to add a contact form. I do not care how I get the contact form data (so just writing this data to a text file in the server will be ok).
What is the simplest solution for this problem? How do people usually handle this?
I believe I can add some server-side code (PHP or something) to handle the form (and write the form data to a file, for instance) but I would prefer a client-side solution.
Use an external tool, they are commonly referred to as "formmailer". You basically submit the form to their server, and they send the form contents via mail to you.
If you don't want that, you have to do something server-sided: Storing data on the server, without having a server side program that accepts the data from the client, is just not possible.
You could install CouchDB and interface that from Javascript :) Everyone could use that then, too :)
The most easy PHP script that stores POST data on your harddisk:
<?php file_put_contents('/path/to/file', serialize($_POST) . "\n", FILE_APPEND); ?>
You can use Google Drive and create form with required fields. and embed code (which will be iframe) in your static web page.
You will be able to get submitted data in spreadsheet.
You can use qontacto . it is a free contact form you can add to any website. it forwards you the messages.
I set up the fwdform service for this exact need.
Just two simple steps to get your form forwarded to your email.
1.Register
Make an HTTP POST request to register your email.
$ curl --data "email=<your_email>" https://fwdform.herokuapp.com/register
Token: 780a8c9b-dc2d-4258-83af-4deefe446dee
2. Set up your form
<form action="https://fwdform.herokuapp.com/user/<token>" method="post">
Email: <input type="text" name="name"><br>
Name: <input type="text" name="email"><br>
Message: <textarea name="message" cols="40" rows="5"></textarea>
<input type="submit" value="Send Message">
</form>
With a couple of extra seconds you can spin up your own instance on Heroku.

can i send data to a javascript function on the server iphone

I i'm wondering if it is possible to call a javascript function from my application. The js function is on the server. Let's say i have a some inputs in the app. Then i have this submit button which calls the IBAction, from the IBAction i want to call:
function mySubmit(){
document.getElementById("myForm").submit();
}
and pass it the data the user entered and then get back a response (in my app) not in the server
Is this possible to do? if so, can you provide some useful links?
Thanks in advance and have a nice saturday ;)
The js function is on the server
Are you sure this is your case? Don't you mean that your js submits a form that is itself treated on the server side?
Javascript is normally a client-side scripting language, which is executed on client-side, contrary to e.g. PHP which is only executed server-side.
[EDIT] (As stated by #Dr.Dredel in the comments, as there exists server-side javascript, but these usages are not yet very common and I don't think it corresponds to your context)
If you need to call a javascript function from an already loaded HTML page in a WebView, you can simply use the UIWebView's stringByEvaluatingJavascriptFromString:. You can pass a string representing javascript code to this function, so you can build a string that represent a function call with string or int arguments for example without any problem.
But if you intend to load your HTML page just to call a javascript fonction which in turn submit a form that sends the form's data to your server… This is clearly the wrong way!
You should instead considering performing the NSURLRequest to your server directly in Objective-C (maybe using ASIHTTPRequest to perform a POST request and easily set the values for each keys of the form you intend to send). In addition, doing this directly in ObjC will avoid loading the HTML page for nothing and rely on the js script, and will allow you to directly get the response in the delegate method.