I've provided the three codes that does the job of displaying the syntax highlighted equivalent of an entered string. But, for some reason, they ain't working. Can anybody solve this problem?
index.html :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="preview.js"></script>
<meta http-equiv="content-type" content="text/html; charset=windows-1250"> <title>Test Code Preview</title>
</head>
<body>
<textarea id="pastecode" rows="20" cols="50" name="pastecode"></textarea>
<br /><input type="text" id="language" name="language"/>
<br /><input type="button" onclick="process()" value="Preview"/>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<div id="previewcode"></div>
</body>
</html>
preview.js :
function process(){
$.ajax({
url: "preview.php",
type: "post",
data: {
pastecode: $("pastecode").val(),
language: $("language").val()
},
success: function(data){
$("#previewcode").html(data);
//Or handle data with jQuery.parseXML()
},
error:function(jqXHR, textStatus, errorThrown){
alert("The following error occured: " + textStatus + " " + errorThrown);
}
}); }
preview.php :
<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
echo '<response>';
if(!empty($_POST['pastecode']) && !empty($_POST['language']))
{
$code=$_POST['pastecode'];
$language=$_POST['language'];
include("geshi/geshi.php");
$path = '';
$geshi = new GeSHi($code, $language, $path);
$geshi->set_overall_style('background-color: #ffffee;', true);
$out = $geshi->parse_code();
echo htmlentities($out);
}
else
{
echo htmlentities("<p>Nothing to display</p>");
}
echo '</response>';
?>
Whats wrong with the code?
I'm filling up the textarea and the language box and pressing the preview button. But no response.