• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Database updating question with JavaScript and local storage

Contributor ,
Sep 14, 2015 Sep 14, 2015

Copy link to clipboard

Copied

Hi all,

I am coming from a PHP background and a newbie with HTML5 and JavaScript and local storage


Currently I'm trying to build a mobile web app that uses a remote Database.

I have a question about database updating.

Currently, I have It set up so when the User logs in successfully – Local storage fields are loaded from the remote database query using a jQuery.get(). This seems to work well.

When it's time to update the data, I populate form fields from the local storage, let the user edit the fields, then:

- use a form post to send the data to the remote php page, which updates the database.....

here's where I have a question: How do I make sure the edit went through okay - what's best to do now?

- I can set up a json response to say if the update was successful or not

or

- Query the database once again and retrieve the fields To compare them to the edit results

or

- Some other technique to Make sure the edit went through okay

- then if successful, I can update the local storage

Q: What is the best way to make sure That the database was updated correctly (and also not waste time with unneeded database access)?

Is there a best practices for this?

Also if possible this newbie could use a clear example...

Views

543

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Sep 14, 2015 Sep 14, 2015

Why not use jquery get()'s callback status where if success is returned then update local storage?

best,

Shocker

Votes

Translate

Translate
Guest
Sep 14, 2015 Sep 14, 2015

Copy link to clipboard

Copied

Why not use jquery get()'s callback status where if success is returned then update local storage?

best,

Shocker

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 14, 2015 Sep 14, 2015

Copy link to clipboard

Copied

Hi the_shocker,

Thanks much for the help

newbie needs clarification... (I tried looking on web but was unsuccessful finding what I need)

so if I have the form sending this...

     $.get("http://mysite.com/edit01.php?ID="+ID+"&firstname="+firstname, function(data, status){

.... etc...

Q: how do I add the callback status to this ?

note: I would like to see something like this....

IF CALLBACK = success

do this...

else

do that...

type thing

Thanks again - DAVE

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 14, 2015 Sep 14, 2015

Copy link to clipboard

Copied

LATEST

The status return is in the callback function. So you'd so something like this:

$.get("http://mysite.com/edit01.php?ID="+ID+"&firstname="+firstname, function(data, status){

     if status == "success" {

          // do success stuff here

     }

     if status == "error"{

          alert('an error occurred during your jquery get request');

     }

});

best,

Shocker

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines