I use jquery and ajax to submit forms without reloading the page, and then depending on the result (whether it is success or error). I am printing a message in two different divs. Since success and error in ajax only checks the client / server connection, I repeat some things from PHP when the request completes successfully, and depending on what I determine what to do with the message. The jquery / ajax part looks like this (usually I use two different divs, but I will use warnings to simplify the example):
success: function (result) { if (result == 'success') { alert("Success!"); } else { alert("There was an error."); } },
This works fine, but I would like to improve its usability.
Now the question arises: can I use something like str.match in the if (result == part? For example, if I had some problems running the request, I would echo in php echo "Error: >error description here<"; Could Am I somehow using str.match(/^Error/) in my if condition and echo the whole message?
source share