I am using jQuery AJAX to call a parameterised function on dynamic button click. Script and function is working fine. only problem is, it is showing all the HTML code into alert box. right from . I don't need to show HTML code, only need to show successfull messages. Please someone help me. Thanks
<html>
tables, textbox, buttons
</html>
<?php
//some php, sql stuff
echo "<td><input type='button' name='disable' value='Disable' onClick='disable($id);'/></td>";
?>
<script>
function disable(id) {
jQuery.ajax({ type: 'Post',
url: '',
data: {action: 'delete', ID: id}
})
.done(function(data) {
alert("Data Saved: " + data);
location.reload();
});
}
</script>
Alert box is showing html code in HTML block and successful messages from php block. I don't need to show HTML code, only need to show successful messages.
I often use this scheme. I do in php
echo "response_ok";
And in javascript i test if php responded with ok this way:
$.get("checkfornew.php", function(data, status)
{
if ( data.indexOf("response_ok") != -1)
{
//response contains "response_ok" string
}
});
Also if you want to display the response from php without html tags you can strip html tags from javascript.But I just display a "response_ok" message from php , and if javascript receive this response it show a html that is already but hidden in the html page.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.