I have simple script which contains two pages – script.php and function.php. Script.php contains one input field with ID #code , one link with ID #submit and jquery function
$('#submit').click(function () {
$.ajax({
url: 'function.php',
type: "POST",
data: "text=" + $("#code").val(),
dataType: 'text',
success: function(data) {
$('#info').html(data);
}
});
return false;
});
How can I clear #code input field value depending on the return result from function.php?
For example, if query is incomplete function.php will only show message in #info field, but if query is complete script will show message and clear input field value.
Consider returning JSON data from function.php, so something like this
Then you can use the jQuery function getJSON.
This means you can return a boolean which decides whether to clear #code or not and also return some html for #info