1

Firstly I'm sorry... the title is not the appropriate but I didn't know how to write this title so... Now, let's to the question... I have a grid and I need to do the following:

I need to verify if some data are on database, and if there isn't, I have to create a row with these data. The problem is that I'm using ajax to send the data to the server(my server file is in php)... but after I send the data how can I do to verify the data on database and then to send these back to the javascript file to show a message to the user like: "These data already exists..." or to insert a new row with these data? Am I so confused?

Thanks in advance!

mailazs
  • 341
  • 6
  • 22
  • 1
    What type of database? You'll have to use PHP to do a search on the database. If there were no results, send back 'No Results' to the AJAX request, otherwise send back 'Data Exists'. Once that's done, update the website with whatever message you want. – AlbertEngelB Apr 30 '13 at 14:25
  • @Dropped.on.Caprica Thanks for reply! I'm using postgres... My problem is that I don't know how to send the "message" back to ajax and then what I have to do to show it... Could you help me? – mailazs Apr 30 '13 at 14:52
  • I'm not 100%, but I would send back a [JSON response along these lines.](http://stackoverflow.com/questions/7294830/sending-encoding-response-in-json) Hopefully that will be enough to get you started. – AlbertEngelB Apr 30 '13 at 15:21

1 Answers1

1

UPDATE: I found an alternative solution (based on this link)... in the php file I sent an echo with true in the if and another echo with false in the else. In javascript file I made something like this:

      $.ajax({
           type: 'POST', 
           url: "edit.php?oper=circ_res",
      })
      .done (function(msg) {
          if(msg == "true"){
             $('#list').trigger('reloadGrid');
          }
          else{
             $('#list').trigger('reloadGrid');
             alert("These data already exists!");
          }
      });

For me, this works... I hope it could help someone :)

mailazs
  • 341
  • 6
  • 22