Skip to main content
Inspiring
September 14, 2015
Answered

Database updating question with JavaScript and local storage

  • September 14, 2015
  • 1 reply
  • 787 views

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...

This topic has been closed for replies.
Correct answer

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

best,

Shocker

1 reply

Correct answer
September 14, 2015

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

best,

Shocker

revdaveAuthor
Inspiring
September 14, 2015

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

September 14, 2015

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