From 8693437cdba0f99320b32f4877c925c9b4697729 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Thu, 1 May 2014 22:53:54 +0200 Subject: [PATCH] Retrieve form data from form instead of url parameters --- js/ConnectingToNetworkPage.js | 7 +++++-- js/JoinSecuredNetworkPage.js | 2 -- js/main.js | 10 +++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/js/ConnectingToNetworkPage.js b/js/ConnectingToNetworkPage.js index 78ea18f..a66d327 100644 --- a/js/ConnectingToNetworkPage.js +++ b/js/ConnectingToNetworkPage.js @@ -15,6 +15,7 @@ var _connectAPI = new ConnectAPI(); var _infoAPI = new InfoAPI(); var _pageData = {}; + var _formData; var _wifiboxid; var _connectedChecking = false; @@ -33,6 +34,9 @@ _pageData = d3d.util.getPageParams(PAGE_ID); var boxURL = "http://"+_pageData.localip; + var form = data.prevPage.find("form"); + _formData = d3d.util.getFormData(form); + _infoAPI.init(boxURL); _networkAPI.init(boxURL); retrieveWiFiBoxID(function() { @@ -60,8 +64,7 @@ } function joinNetwork() { console.log("joinNetwork"); - console.log(" _pageData.password: ",_pageData.password); - _networkAPI.associate(_pageData.ssid,_pageData.password,true); + _networkAPI.associate(_pageData.ssid,_formData.password,true); _connectedChecking = false; } function onRefreshing() { diff --git a/js/JoinSecuredNetworkPage.js b/js/JoinSecuredNetworkPage.js index 43d754b..9d7d975 100644 --- a/js/JoinSecuredNetworkPage.js +++ b/js/JoinSecuredNetworkPage.js @@ -44,8 +44,6 @@ // ToDo: validation // http://www.raymondcamden.com/index.cfm/2012/7/30/Example-of-form-validation-in-a-jQuery-Mobile-Application - var linkParams = _pageData; - linkParams.password = _passwordField.val(); var submitLink = _form.data("target"); submitLink = d3d.util.replaceURLParameters(submitLink,_pageData); $.mobile.changePage(submitLink); diff --git a/js/main.js b/js/main.js index beb71e8..68ca8ed 100644 --- a/js/main.js +++ b/js/main.js @@ -16,7 +16,7 @@ d3d.util = { // Assemble query parameters object from the query string if (hashParts.length > 1) { parameters = {}; - $.each(hashParts[1].split( "&" ), function( index, value ) { + jQuery.each(hashParts[1].split( "&" ), function( index, value ) { var pair = value.split( "=" ); if ( pair.length > 0 && pair[ 0 ] ) { parameters[ pair[ 0 ] ] = @@ -57,6 +57,13 @@ d3d.util = { }, hideLoader:function() { $.mobile.loading('hide'); + }, + getFormData:function(form) { + var formData = {}; + jQuery.each(form.serializeArray(), function(index,field) { + formData[field['name']] = field['value']; + }); + return formData; } }; @@ -73,6 +80,7 @@ d3d.util = { //console.log(" data.toPage: ",data.toPage); if (typeof data.toPage !== "string") { return; } + console.log("pagebeforechange, data: ",data); var url = d3d.util.parseURL(data.toPage); //console.log(" url: ",url); //console.log(" url.hash: ",url.hash);