www.webdeveloper.com
Results 1 to 5 of 5

Thread: Code preview using jQuery not working

Hybrid View

  1. #1
    Join Date
    Jul 2013
    Posts
    31

    Code preview using jQuery not working

    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 :
    HTML Code:
    <!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 :
    Code:
    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 Code:
    <?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.

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    may be you forgot to link up the jQuery script?
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Jul 2013
    Posts
    31
    Quote Originally Posted by Padonak View Post
    may be you forgot to link up the jQuery script?
    Included the jQuery in the html. Now another problem is arising. Now it gives an error.
    The contents of :
    Code:
    alert("The following error occured: " + textStatus + " " + errorThrown);
    is getting displayed.

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Code:
    pastecode: $("#pastecode").val(),
    language: $("#language").val()
    # sings are missed
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  5. #5
    Join Date
    Jul 2013
    Posts
    31
    Quote Originally Posted by Padonak View Post
    Code:
    pastecode: $("#pastecode").val(),
    language: $("#language").val()
    # sings are missed
    I changed the entire jQuery and the PHP. They are now :
    [code=javascript]function process(){
    pastecodeVal = $("#pastecode").val();
    languageVal = $("#language").val();
    $("#previewcode").html("Fetching preview..."+"<hr />")

    $.post("preview.php", { pastecode: pastecodeVal, language: languageVal },
    function(data) {

    $("#previewcode").html(data+"<hr />");

    });
    }[/code]

    PHP :
    PHP Code:
    <?php
        
    if(!empty($_POST['paste']) && !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 
    $out;
        }
        else
        {
            echo 
    "<span style=\"color: red\">Nothing to display</span>";
        }
    ?>
    Its working fine now.!!
    Thanks for the help anyway..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles