I ran into this problem and I cant solve it.
Basically Im making an app for a social network website. Its a forum about computers.
I have no problems loggin in using NSURLConnection and maintain the session. But I cant post a new thread.
Can someone please help me how to do this via obj-c? some code are below here.
html code to submit a new thread
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery.load.min.js"></script>
<script type="text/javascript" src="js/jquery.iphone.js"></script>
<form id="form-newreply" action="/newreply.php" method="post">
<textarea name="message" style="width:95%;height:120px"></textarea><br />
<input type="hidden" name="do" value="postreply" />
<input type="hidden" name="parseurl" value="1" />
<input type="hidden" name="t" value="1375204" />
<input type="hidden" name="loggedinuser" value="170189" />
<input type="hidden" name="p" value="" />
<input type="submit" name="sbutton" value="Send" /></form>
jquery.iphone.js contains this
// reply
$('#form-newreply').live('submit', function(){
$.ajax({
url: '/newreply.php',
data: {
'do': 'postreply', 'parseurl': 1,
't': $(this).find('input[name=t]').val(),
'p': $(this).find('input[name=p]').val(),
'loggedinuser': $(this).find('input[name=loggedinuser]').val(),
'ajax': 1, 'ajax_mobile': 1,
'message': $(this).find('textarea[name=message]').val()
}, type: 'POST', timeout: 20000,
contentType: "application/x-www-form-urlencoded;charset=ISO-8859-1",
success: function(data){
if (data.match(/postid:(\d+)/)) {
var sID = data.replace(/postid:/, '');
loadPage('sp-' + sID + '.html#p' + sID);
} else {
var aM = data.match(/<!--POSTERROR do not remove this comment-->([^<]+)?<ol><li>([^<]+)/);
if (aM && aM.length == 2 && aM[1].length) {
alert(aM[0]);
} else {
alert('ERR');
}
}
}
});
return false;
});
I was able to do it using this plugin:http://allseeing-i.com/ASIHTTPRequest/How-to-use
Related
I currently have autocomplete functionality on the results page using Google custom search, but how can I see autocomplete display in a separate custom search box?
<script type="text/javascript">
$(document).ready(function () {
$("#googleCseSearchTextBox").keypress(function (e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) { //Enter keycode
googleCseSubmit();
return false;
}
});
$("#googleCseSearchButton").click(googleCseSubmit);
});
function googleCseSubmit() {
window.location.href = "my site and key" + $('<div/>').text($("#googleCseSearchTextBox").val()).html();
};
</script>
Custom search box:
<div>
<fieldset class="sfsearchBox">
<input name="googleCseSearchTextBox" type="text" id="googleCseSearchTextBox" class="sfsearchTxt" />
<input type="button" value="Search" id="googleCseSearchButton" class="sfsearchSubmit" />
</fieldset>
</div>
Thanks
Insert this code on the your first page for autocompletion. Don't forget to add your own google id below.
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1');
google.setOnLoadCallback(function(){
google.search.CustomSearchControl.attachAutoCompletion(
'your-google-search-id',
document.getElementById('search-field'),
'search-form');
});
</script>
<!-- example search form -->
<form id="search-form" action="/search">
<input id="search-field" name="search-field" type="text" />
<input type="submit" value="Search" />
</form>
Also check here for more reference
https://developers.google.com/web-search/docs/
I am using PassportJS with my ExpressJS app and I am trying to set up a password confirmation field with my user sign up. My original thought is to make this a view/controller setup rather than involving a model to simplify this process, but I am having an issue with the way I am trying to achieve this logic as my passportJS localStrategy is not checking that the two field values match. Am I approaching this in the right manner?
PassportJS logic (req.user && password === confirmPassword):
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var models = require('../app/models/db-index');
var bcrypt = require('bcrypt-nodejs');
//Sign Up Logic
passport.use('local-signup', new LocalStrategy({
passReqToCallback: true,
usernameField: 'email'
}, function(req, email, password, done){
models.User.findOne({
where: {
email: email
}
}).then(function(existingUser){
if (existingUser)
return done(null, false, req.flash('error', 'Email already exists.'));
if (req.user && password === confirmPassword) {
var user = req.user;
user.firstName = firstName;
user.lastName = lastName;
user.email = email;
user.password = models.User.generateHash(password);
user.save().catch(function(err){
throw err;
}).then(function(){
done(null, user, req.flash('error', 'All fields need to be filled in'));
});
} else {
var newUser = models.User.build({
firstName: req.body.firstName,
lastName: req.body.lastName,
email: req.body.email,
password: models.User.generateHash(password)
});
newUser.save().then(function(){
done(null, newUser);
}).catch(function(err){
done(null, false, console.log(err));
});
}
}).catch(function(e){
done(null, false, req.flash('error', 'All fields need to be filled in'),console.log(e.email + e.message));
})
}));
Route:
*==== /SIGN-UP ====*/
siteRoutes.route('/sign-up')
.get(function(req, res){
res.render('pages/site/sign-up.hbs',{
error: req.flash('error')
});
})
.post(passport.authenticate('local-signup', {
successRedirect: '/app/sign-up/organization',
failureRedirect: '/sign-up'
}));
View:
<!DOCTYPE html>
<head>
{{> site/head}}
</head>
<body>
{{> site/navigation}}
<div class="container">
<div class="col-md-6 col-md-offset-3">
{{#if error}}
<div class="alert alert-danger">{{error}}</div>
{{/if}}
<h1>Sign Up</h1>
<form action="/sign-up" method="post">
<input type="text" class="form-control" id="sign-up-fist-name" name="firstName" value="" placeholder="First Name">
<br />
<input type="text" class="form-control" id="sign-up-username" name="lastName" value="" placeholder="Last Name">
<br />
<input type="text" class="form-control" id="sign-up-username" name="email" value="{{user.email}}" placeholder="Email">
<br />
<input type="password" class="form-control" id="sign-up-password" name="password" value="" placeholder="Password">
<br />
<input type="password" class="form-control" id="sign-up-password" name="confirmPassword" value="" placeholder="Confirm Password">
<button type="submit">Submit</button>
</form>
Already have an account? Login here!
</div>
</div>
</body>
If you can't find solution, use javascript confirmation. It's simplest way which I use. If you find solution, please share her, I wanna use it.
<script>
function myFunction() {
var password = document.getElementById("password").value;
var password2 = document.getElementById("password2").value;
var ok = true;
if (password != password2) {
//$(".alert").alert();
//alert("Passwords Do not match");
document.getElementById("alert").style.display = 'block';
document.getElementById("password").style.borderColor = "#E34234";
document.getElementById("password2").style.borderColor = "#E34234";
ok = false;
} else {
alert("Passwords Match!!!");
}
return ok;
}
</script>
I started to use Pubnub for making video group chats. However, when I was testing it, I found a little problem: As I connect my computer to their servers, my webcam turns on and never turns off, unless I leave the page.
However, I wish to be able to close a video chatting, and turning off the webcam at the same time. How to do it?
Thank you very much!
EDIT: Here is a code I'm using for my tests, I'm using the one given in the tutorial:
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/pubnub-3.7.18.min.js"></script>
<script src="js/webrtc.js"></script>
<script src="js/rtc-controller.js"></script>
<div id="vid-box"></div>
<div id="vid-thumb"></div>
<form name="loginForm" id="login" action="#" onsubmit="return login(this);">
<input type="text" name="username" id="username" placeholder="Pick a username!" />
<input type="submit" name="login_submit" value="Log In">
</form>
<form name="callForm" id="call" action="#" onsubmit="return makeCall(this);">
<input type="text" name="number" placeholder="Enter user to dial!" />
<input type="submit" value="Call"/>
</form>
<div id="inCall"> <!-- Buttons for in call features -->
<button id="end" onclick="end()">End</button> <button id="mute" onclick="mute()">Mute</button> <button id="pause" onclick="pause()">Pause</button>
</div>
<script>
var video_out = document.getElementById("vid-box");
var vid_thumb = document.getElementById("vid-thumb");
function login(form) {
var phone = window.phone = PHONE({
number : form.username.value || "Anonymous", // listen on username line else Anonymous
media : { audio : true, video : true },
publish_key : 'pub-c-c66a9681-5497-424d-b613-e44bbbea45a0',
subscribe_key : 'sub-c-35aca7e0-a55e-11e5-802b-02ee2ddab7fe',
});
var ctrl = window.ctrl = CONTROLLER(phone);
ctrl.ready(function(){
form.username.style.background="#55ff5b"; // Turn input green
form.login_submit.hidden="true"; // Hide login button
ctrl.addLocalStream(vid_thumb); // Place local stream in div
}); // Called when ready to receive call
ctrl.receive(function(session){
session.connected(function(session){ video_out.appendChild(session.video); });
session.ended(function(session) { ctrl.getVideoElement(session.number).remove(); });
});
ctrl.videoToggled(function(session, isEnabled){
ctrl.getVideoElement(session.number).toggle(isEnabled); // Hide video is stream paused
});
ctrl.audioToggled(function(session, isEnabled){
ctrl.getVideoElement(session.number).css("opacity",isEnabled ? 1 : 0.75); // 0.75 opacity is audio muted
});
return false; //prevents form from submitting
}
function makeCall(form){
if (!window.ctrl) alert("Login First!");
else ctrl.dial(form.number.value);
return false;
}
function end(){
ctrl.hangup();
}
function mute(){
var audio = ctrl.toggleAudio();
if (!audio) $("#mute").html("Unmute");
else $("#mute").html("Mute");
}
function pause(){
var video = ctrl.toggleVideo();
if (!video) $('#pause').html('Unpause');
else $('#pause').html('Pause');
}
</script>
Note that I tried to find the function through the console in addition to my searches, but I was unable to find it...
I am a newbie and tried to do the laziest way to do a file upload using emberjs, jquery and formdata(IE10+). The code might look stupid, but it worked.
Here is what i got. Can you please take a look and give some suggestions. Am i doing it wrong?
<script type="text/x-handlebars" data-template-name="posts">
<form role="form" enctype="multipart/form-data" method="post" id="fileinfo" {{action 'createPost' on='submit'}}>
{{input type="text" value=newPost id="newPost" placeholder="Post" class="form-control"}}
{{input type="file" id="inputFile" class="form-control" name="file"}}
<button type="submit" class="btn btn-default" >Submit</button>
</form>
</script>
App.PostsController = Ember.ArrayController.extend({
actions: {
createPost: function(){
var fd = new FormData(document.getElementById("fileinfo"));
fd.append("postContent", this.get('newPost'));
this.set('newPost', ''); //reset text field
$('#inputFile').val(''); //reset fileinput field
Ember.$.ajax({
url: "http://localhost:3000/posts",
type: "POST",
data: fd,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
});
}
}
});
I'm doing an xhr file upload using dojo.io.iframe.send and it works fine in all browsers except IE 8. IE8 sends a GET request instead of a multipart POST. This is my code:
dojo.io.iframe.send({
form: this.logoForm.domNode,
handleAs: "json",
method: "POST",
url: '/backend/design/uploadLogo',
load: dojo.hitch(this, function(response) {
if (response.error) {
errorFunc(response);
} else {
this.submitStatusLogo.innerHTML = "Your logo has been successfully uploaded.";
this.logoButton.hideIndicator();
dojo.addClass(this.submitStatusLogo, "success");
if (response.logoPath) {
this.productLogo.innerHTML = '<img src="'+response.logoPath+'" alt="" />';
}
}
}),
error: errorFunc
});
And this.logoForm.domNode is:
<form dojoAttachPoint="logoForm" dojoType="dijit.form.Form" enctype="multipart/form-data" class="designLayoutForm">
<div class="uploadedImage" dojoAttachPoint="productLogo"></div>
<h2>Logo
<span dojoType="sc2.common.TinyHelp" title="Logo">
Upload a product logo that will be shown in the top left of the demo page.<br />
If the logo is higher than 80 pixels, it will be resized to a height of 80px. <br />
<br />
<i>Supported file types are: png, jpg, gif, bmp.</i>
</span>
</h2>
<p>
<input type="hidden" dojoAttachPoint="logoForm_product" name="product" value="" />
<input type="hidden" dojoAttachPoint="logoForm_XSessionVerify" name="X-Session-Verify" value="" />
<input type="file" name="file" dojoAttachPoint="logoInput" />
</p>
<p dojoAttachPoint="submitStatusLogo" class="submitStatus"></p>
<p>
<input dojoType="sc2.form.IndicatorButton" dojoAttachPoint="logoButton" label="Upload">
</p>
</form>
What am I doing wrong?
Okay I solved it, adding method="POST" to the form element did the trick. Apparently specifying method: "POST" in the send parameters was not sufficient for IE8. Thanks for your time anyway