1

When I press "btnNew" the click event fires but the page does not navigate to newLanguagePage, instead it goes back to my initial page (index.html). Could anyone, please, tell me what my dumb head is doing wrong?

Here's my HTML

<!DOCTYPE html> 
<html>
<body> 

<div id="languagesAdmin" class="mobilePage" data-role="page">

    <div data-role="header">
        <a href="#" data-rel="back" data-icon="back">Back</a>
        <h1>NOTHNG</h1>
        <a href="help.html" data-icon="info">Help</a>
    </div> 

    <div class="banner">
        <div class="logo"></div><div id="languagesTopImage" class="topBannerImage"></div>
    </div>

    <div class="ui-corner-all custom-corners">
        <h2 class="ui-bar ui-bar-e adminHeader">Languages Menu</h2>
        <div class="ui-body ui-body-e">
            <div data-role="fieldcontain" class="filterDisabledCheckbox">
                <label for="HideDisabledLanguages">Hide disabled Languages</label>
                <input type=checkbox id="HideDisabledLanguages" name="HideDisabledLanguages" value="true" checked/>
            </div>
            <ul data-role="listview" id="lwLanguages" class="listViewMenu"></ul>
        </div>
    </div>

    <div data-role="footer" data-position="fixed">
        <div data-role="navbar">
            <ul>
                <li><a id="btnNew" href="#" rel="external" data-role="button" data-icon="plus">New</a></li>
                <li><a href="index.html" data-role="button" data-icon="delete">Delete</a></li>
                <li><a href="index.html" data-role="button" data-icon="search">Search</a></li>
                <li><a href="index.html" data-role="button" data-icon="refresh">Refresh</a></li>
            </ul>
        </div>
    </div>
</div>

<div id="newLanguagePage" class="mobilePage" data-role="page">

    <div data-role="header">
        <a href="#" data-rel="back" data-icon="back">Back</a>
        <h1>Inter&nbsp;Pay&nbsp;Less</h1>
        <a href="help.html" data-icon="info">Help</a>
    </div> 

    <div class="banner">
        <div class="logo"></div><div class="topBannerImage"></div>
    </div>

    <div class="ui-corner-all custom-corners">
        <h2 class="ui-bar ui-bar-e adminHeader">Languages Menu</h2>
        <div class="ui-body ui-body-e">
            New Language
        </div>
    </div>

    <div data-role="footer" data-position="fixed">
        <div data-role="navbar">
            <ul>

                <li><a href="index.html" data-role="button" data-icon="delete">Delete</a></li>
                <li><a href="index.html" data-role="button" data-icon="search">Search</a></li>
                <li><a href="index.html" data-role="button" data-icon="refresh">Refresh</a></li>
            </ul>
        </div>
    </div>
</div>

</body>
</html>

Here's the JavaScript

var strBaseWSURL = "http://www.WHATEVER.com/";

var objLanguages = new Array();
var lngLanguagesCursor = -1;

//Language Object
function _Language(data) {
    this.Id = data.Id;
    this.Code = data.Code;
    this.Name = data.Name;
}


//LanguageAdmin_pageinit
$(document).on('pageinit', '#languagesAdmin', function () {

    try {
        execJQueryAjaxAndGetJSON([], strBaseWSURL + "IPLObjectsWS.asmx/GetAllLanguages", loadLanguages);
    }
    catch (e) {//Report the error
        alert("Error fetching the languages.")
        return false;
    }

    //New_Click
    $(document).on("click", "#btnNew", function () {
        $.mobile.navigate("#newLanguagePage", { transition: "slide" });
    });

    //Languages_onclick
    $(document).on("click", "#lwLanguages li a", function () {
        lngLanguagesCursor = $(this).closest("li").index();
    });
});

//LanguageDetails_pageinit
$(document).on('pageinit', '#languageDetails', function () {
    var objCurrentObject = objLanguages[lngLanguagesCursor];
    $("#languageid").val(objCurrentObject.Id);
    $("#languagecode").val(objCurrentObject.Code);
    $("#languagename").val(objCurrentObject.Name);

    //Save_onclick
    $(document).on("click", "#btnSaveCountry", function () {
        var objCurrentObject = objLanguages[lngLanguagesCursor];

        var objUpdatedLanguage = new _Language();
        objUpdatedLanguage.id = objCurrentObject.id;
        objUpdatedLanguage.Code = $("#languagecode").val();
        objUpdatedLanguage.Name = $("#languagename").val();

        execJQueryAjaxAndGetJSON(objUpdatedLanguage, strBaseWSURL + "IPLObjectsWS.asmx/SaveLanguage", savedLanguage);
    });
});

//__________________________________________________________________________Application Functions
//__________________________________________________________Calback functions
//Goes thru the languages and adds them to the lisview
function loadLanguages(result) {
    $.each(result.d, function () {
        $("#lwLanguages").append($('<li><a href="language_details.html">' + this.Name + '</a></li>'));
        objLanguages[objLanguages.length] = new _Language(this);
    });
    $("#lwLanguages").listview("refresh");
}

function savedLanguage(result) {
    alert("The object was saved successfully!");
}

//__________________________________________________________Main functions
//Executes a Webservice Method and send the returned JSON to a callback function
function execJQueryAjaxAndGetJSON(params, strURL, callBackFunc) {

    //GetCountries
    $.ajax({
        type: "POST",
        url: strURL,
        data: params,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: callBackFunc,
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus + ": " + XMLHttpRequest.responseText + "\n" + errorThrown);
        }
    });
}
  • possible duplicate of [how to change page in latest jquery mobile (1.4 beta)?](http://stackoverflow.com/questions/19174611/how-to-change-page-in-latest-jquery-mobile-1-4-beta) – Omar Jan 06 '14 at 15:10
  • Use `$.mobile.pageContainer.pagecontainer("change", "#page", { options });`. – Omar Jan 06 '14 at 15:42
  • @Omar: Yes, i've tried that too but it does not work either. It makes the same result... nothing... :( I made a simple "2 page multipaged page" and it worked. but together with the rest of the code it does not work. when i check the adress bar, it point to the root root/#newLanguagePage which is not the correct adress... it should be root/languages.html#newLanguagePage... Im new into jQuery Mobile... but know quit a lot JS. And I really would like to implement it for this new project. Thanks for a fast reply Mr. Omar. – Dan The Man Jan 06 '14 at 15:55
  • So you're using _single page model_ and _multi-page model_, right? If yes, you can't combine both models, it's either _single_ or _multi_. – Omar Jan 06 '14 at 15:58
  • Do I have to choose model for the entire project??? Cant I start say, with single model and then in some pages use a multi page model? – Dan The Man Jan 06 '14 at 16:52
  • In this case, you need to link pages with `rel="external` and load them normally through HTTP. Mixing both models using Ajax isn't possible. So when changing pages programmatically by using `$.mobile.pageContainer.pagecontainer("change", "URL", { reload: true });` you need to set `reload` to true. Note that this option works only with _URL_ not hashtag page. – Omar Jan 06 '14 at 16:55
  • No you really should not mix both models – imaginethepoet Jan 07 '14 at 13:25

0 Answers0