问题
I'm successfully using jeditable to submit via a function using jQuery.ajax and the async : false option , but am having an issue aborting if an error is returned.
How can I get the edit box to stay activated and / or revert back to the original value if there are errors? I'm returning http status codes.
so something like
async : false .ajax submit here...
if (xhr.status == 200) {
return value;
else {
alert ('returned error');
// keep edit box activated but available for another try, or revert back to original value
}
I tried not returning a value from the function, which keeps the edit box activated and ready for another submit, but then the ESC key doesn't work anymore and if I click outside the edit area, the edit box stays.
Thanks in advance!
回答1:
Not sure if this helps in your situation, but jeditable has a reset method in it...
try...
this.reset();
this will revert the element back to display mode with the original value.
回答2:
To stay in editmode,just set response header "HTTP 404" and render a error text.
PHP:
header('HTTP/1.1 400 Bad Request');
echo "Error Text";
回答3:
Add this:
$(this).editable("disable");
This should stop your errors from being editable, not sure about reverting back. I am kinda fighting the same issue with reverting back right now, but i know nothing about JavaScript...
来源:https://stackoverflow.com/questions/727973/jquery-jeditable-stay-in-edit-mode-on-error