Welcome Guest, Not a member yet? Register   Sign In
jQuery AJAX Success Callback
#1

[eluser]jamgood96[/eluser]
I'm working starting back to work a database for my company after almost two months away from it. I made fair progress previously, but am finding a few issues I left unresolved and have no idea how to address right now.

The main one is in my "add client" portion of the code. Right now, I have a css popup box load with a form to input new client information. Once submitted, the data is validated and if all is good, the data is input into the database. If it is not correct, the form shows errors.

The issue I am having is that once the form is submitted and validated, I need to have the pop-up close and the page refresh via AJAX to load the new client's information. This means that a clientID number needs to be passed back if successful, otherwise the HTML data needs to be reloaded into the form to show the errors.

Any ideas how to go about this? This is little tricky for me to relay, so if you need more information I'd be more than happy to give it.

Thanks!

Code:
function validateClientInfo(telephone,telephone2) {
//alert('sending to validate');
$.ajax({
  url: "addPopUp/validate",
  type: "POST",
  dataType: "html",
  data: $('#addClientForm').serialize() + "&telephone;=" + telephone + "&telephone2;=" + telephone2,
  success: function(html) {
   alert(html);
   if (html=="success") {
    closePopUpBox();
    loadClient(html);
   } else {
    openPopUpBox(html);
   }
  }
});
}
#2

[eluser]CroNiX[/eluser]
It looks like addPopUp::validate() just returns text, like 'success'. How about return a json object with the status and the id. Then it looks like you would just pass the id to loadClient()?

Either that or I assume you are passing the ID somehow in your form? If so, you could just grab the id from there and just:
Code:
if (html=="success") {
    closePopUpBox();
    var id = $('#form-element-with-id').val();
    loadClient(id);
}
#3

[eluser]jamgood96[/eluser]
Problem is there is no id created until it has been input into the actual database, so I don't know how the 'var id' would work.

As for returning a json object, how would I go about that?
#4

[eluser]CroNiX[/eluser]
With json_encode()




Theme © iAndrew 2016 - Forum software by © MyBB