jQuery code does not work in phonegap

Someone gave me a code https://jsfiddle.net/adeneo/2uod274d/ jsfiddle

It works well in jsfiddle, but when I put the code in my Xcode and amended to incorporate my code and run it in the Simulator, the code does not work at all (i.e., no data is stored in the local storage)

I am building an app for iOS with phonegap. JS:

<script type="text/javascript" src="cordova.js"></script>
  
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
  
<script type="text/javascript" src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>

  
<script type="text/javascript">
  document.addEventListener("deviceready",onDeviceReady,false);

  function onDeviceReady() {

  document.getElementById("btnSave").addEventListener("click",saveData,false);
  document.getElementById("btnShow").addEventListener("click",showData,false);
}

  function saveData(){
  var data = window.localStorage.getItem("date");

  var dates = data ? JSON.parse(data) : [];

  dates.push( new Date() );

  window.localStorage.setItem("date", JSON.stringify(dates));

  alert("Your data is stored");
  }

  function showData() {
  var data = JSON.parse(window.localStorage.getItem("date"));
  console.log(data);
  $('#res').html(JSON.stringify(data));
  $(this).html('Update result');
  }

< /script >

HTML:

<button id="btnSave"> Save Data </button>

  
<button id="btnShow"> Show Data </button>

I don't know what is happening because the code works well in jsfiddle, but for some reason any just does not work in my phonegap.

My version of phonegap 5.3.6 cordova version 5.3.3

Post edited by: Fang Kerry, I added my complete code is easier to see the problem (if any)

jQuery has nothing to do with this, as far as I can tell (so not sure why it is in your title). The problem is that the result of JSON.parse (data) is not an array, what you think it is, it's a chain. The chain respond well to 'push '. I get that when you use this code in jsfiddle he is somehow coming out as a table, but I think it must be because of something done jsfiddle. When I do the same commands in the console of my browser, I get a string, not a table, so your problem.

Instead:

function deserializeDates() {
    var data = window.localStorage.getItem("date");
    var dates = []; // worst case, we'll return an empty array.
    if (data) {
        try {
            dates = JSON.parse(data);
             // handle the case that dates is a single item and not an array
            if (!(dates instanceof Array)) {
                dates = [dates];
            }
        } catch (err) {
             // the stored dates failed to parse for some reason; you might want to do something about it
             console.log("Failed to parse " + data);
         }
    }
    return dates;
}

function serializeDates(dates) {
    window.localStorage.setItem("date", JSON.stringify(dates));
}

function saveData(){
     var dates = deserializeDates();
    dates.push( new Date() );
     serializeDates(dates);
    alert("Your data is stored");
}

function showData() {
     var dates = deserializeDates();
    console.log(dates);
    ...
  }

Tags: PhoneGap

Similar Questions

  • A refurb Lenovo/IBM PC windows 7.0 SW, software code does not work for charging SW after a system restore

    A refurb Lenovo/IBM PC windows 7.0 SW, software code does not work for charging SW after a system restore. How can I get a new one

    Skip, enter the product key, and then complete the installation.

    Try the phone activation:

    How to activate Windows 7 manually (activate by phone)
     
    1) click Start and in the search for box type: slui.exe 4
     
    (2) press the ENTER"" key.
     
    (3) select your "country" in the list.
     
    (4) choose the option "activate phone".
     
    (5) stay on the phone (do not select/press all options) and wait for a person to help you with the activation.
     
    (6) explain your problem clearly to the support person.
     
    http://support.Microsoft.com/kb/950929/en-us

  • Reinstall Windows 7 and now the activation code does not work

    I upgraded my PC with an AM2 chip to an i5.  I had to reinstall windows and now my activation code does not work.   It's like 2-3 years, I forgot when I built the computer.  It installed on my other windows 7 install and created the windows.old folder.  How can I get reactivated?  I used the same code since I built my computer.

    Thank you

    Have you tried to restart by phone?

    How to activate Windows 7 manually (activate by phone)
     
    1) click Start and in the search for box type: slui.exe 4
     
    (2) press the ENTER"" key.
     
    (3) select your "country" in the list.
     
    (4) choose the option "activate phone".
     
    (5) stay on the phone (do not select/press all options) and wait for a person to help you with the activation.
     
    (6) explain your problem clearly to the support person.
     
    http://support.Microsoft.com/kb/950929/en-us

  • I have Adobe Creative Suite 5 Master Collection. Activation code does not work?

    I have Adobe Creative Suite 5 Master Collection. Activation code does not work when I install it on my Macbook. It installed properly on my Windows PC, however.

    I thought the serial numbers for specific version CS5... Mac - GOLD - Windows, not both

    You sure have a serial number which is good for both?

  • Lightroom6 installation code does not work

    I'm tired, the installation code does not work.

    After 10 days, there is no way to be supported by Adobe, but they took my money.

    I'll block the payment and never again buy Lightroom.

    Mac or Windows and EXACTLY what version of the operating system?

    Recent Mac AND Windows operating systems have been known to cause problems "weird."

    Since this is an open forum, not Adobe support... you must contact Adobe personnel to help

    Chat/phone: Mon - Fri 05:00-19:00 (US Pacific Time)<=== note="" days="" and="">

    Don't forget to stay signed with your Adobe ID before accessing the link below

    Creative cloud support (all creative cloud customer service problems)

    http://helpx.Adobe.com/x-productkb/global/service-CCM.html

    -or by phone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html

  • Why my license code does not work on lightroom 6 for mac?

    Why my license code does not work on lightroom 6 for mac? My os x is "el capitan".

    Please try the steps to serialize Lightroom CC trial to activate like Lightroom 6 mentioned on: https://helpx.adobe.com/lightroom/kb/serialize-lightroom-cc-trial-to-activate-as-lightroom - 6.html

    You can also try: error "serial number is not valid for this product". Creative Suite

  • my serial code does not work how can I make it work

    my serial code does not work how can I make it work thank you

    Hello

    If you have a creative cloud subscription then you do not require a serial number to activate it, all you need to do is sign with your ID (Email used at purchase) Adobe in creative application Cloud to activate your membership. See,

    Connect and disconnect activate Cloud Creative applications

    Solve common problems of activation and deactivation of creative cloud.

    Activation and deactivation of troubleshooting

    Find solutions to activation errors that may occur during the launch of Adobe applications.

    I checked with your Adobe Id on the forums that there is no active subscriptions to this topic.

    If you have any other Adobe id try please activate the products with that.

    Kind regards

    Bani

  • Coupon code does not work and has not been used before - stale code? Software purchased in 2011

    I was trying just to 'chat' with someone, and they're signing. My CS5 coupon code does not work on my computer - I'm re-entered several times to ensure that there are no errors. It has not been used before. I bought the [Mac] software in 2011 and was able at the time to buy a Mac to install the software on. Does anyone have advice? Or y at - it someone with Adobe that can help?

    Using redemption code

    Contact adobe support, https://helpx.adobe.com/contact.html

  • Why my registration code does not work?

    I just bought Adobe Photo Shop Elements for MAC and provided in the box registration code does not work.  Now, I can't find my serial number.  I got the purchase at Best Buy and they told me that since it was open, I call Adobe.  I was not able to find the phone numbers for support and all redirects me here.  I really want to use this product before the weekend and now I'm beyond frustrated.  I did research on research and nothing helped.

    Can you help me?

    AA I mentioned above, I tried everything recommended on Adobe's Support site. I was not able to find something that works with your link above.

  • VM WS 7 coupon code does not work.

    as shown in the promo code topic, that I was sent for Workstation 7 does not work.

    Now before anyone asks,

    I used IE, Mozilla and Chrome

    I have cleared all caches

    I restarted the system in its entirety

    I typed in the code - not cut and pasted

    promo code does not work.

    Assistance received with gratitude.

    concerning

    See http://communities.vmware.com/thread/239311?tstart=0

  • My redemption for Adobe Acrobat XI code does not work. What should I do?

    My redemption for Adobe Acrobat XI code does not work. What should I do?

    Have you tried the steps listed here?

    http://helpx.Adobe.com/x-productkb/policy-pricing/serial-number-retrieval-process-FAQ.html

  • The JavaScript code does not work

    Thank you for this beautiful prduct comfortable, but when I try it in any site uses javascript code does not work.

    Open this link: http://view.jquerymobile.com/1.3.1/demos/widgets/panels/ and try clicking the buttons (nothing will happen).

    Yes. To be clear, you must click on the device to see work.

  • period overlaps the code does not work in apex page

    Hello

    Employees have a schedule with a start date and end. Calendar periods cannot overlap for the same employee.

    I have a function that returns the error of validation of text as follows:

    declare
    number of l_dummy;

    Start
    Select count (*)
    in l_dummy

    of fus_medewerker_roosters
    where mdr_code =: p61_mdr_code
    and <>id: p61_id
    and to_date(:p61_begin_periode,'DD-MON-YY') < = eind_periode
    and to_date(:p61_eind_periode,'DD-MOn-YY') > = begin_periode
    +;+

    If l_dummy > 0
    then
    Back to 'this employee already has a calendar in this period.';
    on the other
    Returns a null value.
    end if;

    end;

    But the code does not work. It records data of an employee even though the periods overlap.

    But the code works correctly in workshop:

    declare
    number of l_dummy;

    Start
    Select count (*)
    in l_dummy

    of fus_medewerker_roosters
    where mdr_code =: p61_mdr_code
    and <>id: p61_id
    and to_date(:p61_begin_periode,'DD-MON-YY') < = eind_periode
    and to_date(:p61_eind_periode,'DD-MOn-YY') > = begin_periode
    +;+

    If l_dummy > 0
    then
    DBMS_OUTPUT. Put_line ("this employee already has a calendar at this time."); end if;

    end;

    What goes wrong. Why it works very well in the Studio, but not in my page?

    Kind regards
    Diana

    Edited by: dianap on Sep 4, 2009 08:31

    Hi Diana,

    It comes with the following:

    to_date(begin_periode,'DD-MON-YYYY')
    

    and

    to_date(eind_periode,'DD-MON-YYYY')
    

    Here are the dates of the table itself, should not be converted to dates.

    Secondly and more important still, the list of selection of P11_MDR_ID does not return NULL, it returns "null %" - it is a string that should be converted to null.

    I have made a few changes for postings of these - please take a look and check that everything is working ok.

    Andy

  • I nee a new code, my code does not work

    Dear Sir or Madam,

    a friend restalled my laptop and I need a new code for my window at work, because my old code does not, please could you give me the phone number to get a new code or could you give me a new code.

    Thank you

    Yours sincerely

    bobsargent

    Hello

    You don't need to buy a new product key.

    Use the appropriate method of re-setup to reinstall Vista and activate it.

    There are several methods to reinstall Vista.

    There is no Windows Vista downloads available from Microsoft.

    You can contact your computer manufacturer and ask them to send you a set of recovery disks.

    They should do this for a small fee.

    To reinstall Vista using their recovery disk/s, you start from the 1st recovery disk they provide and follow the manufacturer's instructions to reinstall:

    You need to change the Boot order to make the DVD/CD drive 1st in the boot order:

    How to change the Boot order in BIOS:

    http://pcsupport.about.com/od/fixtheproblem/SS/bootorderchange.htm

    "How to replace Microsoft software or hardware, order service packs and replace product manuals.

    http://support.Microsoft.com/kb/326246

    And if you have never received a recovery disk when you bought your computer, there should be a recovery Partition on the hard drive to reinstall Vista on how you purchased your computer.

    The recovery process can be started by pressing a particular combination of the key or keys at startup. (Power on / start)

    Maybe it's F10, F11, Alt + F10, etc., depending on the manufacturer.

    Ask them to the proper key sequence.

    And if you do not score a manufacturer of recovery on your hard drive, you should be able to make your own recovery from her disks to reinstall the operating system.

    Go to programs > name of the manufacturer of your computer > then their system or recovery tools software topics for them, depending on how it is formulated.

    If you can't find any reference to it, contact the manufacturer for advice on how to make these recovery disks.

    Some manufacturers have more available Vista recovery disks.

    If this happens, you may need to try this instead:

    You can also borrow and use a Microsoft Vista DVD, which contains the files for the different editions of Vista (Home Basic, Home Premium, Business and Ultimate) must be installed. The product key on your computer / Laptop box determines what Edition is installed.

    Other manufacturers recovery DVDs are should not be used for this purpose.

    And you need to know the version of 'bit' for Vista, as 32-bit and 64-bit editions come on different DVDs

    Here's how to do a clean install of Vista using a DVD of Vista from Microsoft:

    "How to do a clean install and configure with a full Version of Vista '

    http://www.Vistax64.com/tutorials/117366-clean-install-full-version-Vista.html

    And once the operating system is installed, go to your computer manufacturer's website and get the latest drivers for your particular model or laptop computer.

    And phone Activation may be necessary when you use the above installation method.

    "How to activate Vista normally and by Activation of the phone '

    http://www.Vistax64.com/tutorials/84488-activate-Vista-phone.html

    See you soon.

  • MrFixIt of E0434F4D program for the error code does not work because of this error

    When you install the update for Microsoft .NET Framework 1.1 SP1, I get the error E0434F4D code.  MrFixIt program does not work because of this error. I can't run applications because of this corruption. Including most Microsoft applications, as soon as I try to run an application, I get a window saying 'a problem caused blocking the program works correctly. Windows will close the program and notify you if a solution is available. "I recently got this used pc and I looked at the history of the update, and it was apparently a failed update for the past two years. This will also prevent me to update other software and drivers on my computer and prevents even me to install new drivers.

    Hello

    1 have had any changes made on the computer before the show?

    2. when exactly you get the error message?

    3. what happens when you try to run Microsoft Fix it?

    4. What is the full and exact error message?

    I suggest you check the thread with a similar problem, and a fix:

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-windows_update/error-code-e0434f4d-what-to-do-to-fix-this/10ac1da2-25AC-495a-a8a5-6dbe2809f7a0

    If you are having problems with Microsoft Fix it tools, I suggest you to send your request in the Microsoft Fix it forums for assistance.

    Microsoft Fix it Forum

    http://social.Microsoft.com/forums/en/fixitcenter/threads

Maybe you are looking for

  • How can I edit a copy scanned pages in El Capitan

    I scanned a document and now need to change it. It's in the preview, I use a MacMini running El Capitan, I get just a hand symbol which does ' t allow the amendment.

  • Toshiba virtual Store account Reset - 23307

    HelloYou can reset the personal account - 23307 please.Thank you

  • DV9715nr mic not working not not in Win7

    Just clean installed Win 7 Ultimate x 64, built in mic is more work. In Control Panel > Sound > recording tab, device listed is the Microphone (High definition audio device - not connected), says he uses the 3.5 mm jack. Right of the mouse clicked, s

  • Change the size of the text

    Someone changed the size of the text in my computer, including desktop.  How to return to the original size (defaualt)?

  • USB keys deleting leads to the failure of the system of

    Dear representative of Microsoft, I am facing a problem with my USB keys deleting. When I remove my USB port on my desktop (Windows 7), I have a reboot of the system. I think it is a problem of software security and I hope you can tell me the name of