#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Burb of Detroit, Michigan
    Posts
    92
    Rep Power
    78

    PHP, JSON, AJAX and jQuery(JavaScript) Help


    I've been stumped for over a week on the this, I am using jQuery and PHP to have it where a visitor doesn't have to refresh the page. I have it working in Fireforx and Chrome, but every time I use Internet Explorer 10 it crashes.

    Here is my HTML file:
    editPage.html
    Code:
    <!DOCTYPE html>
    <html>
        <head>
            <title>Edit Title & Content</title>
            <link href="css/stylesheet_jquery.css" rel="stylesheet">
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
            <script type="text/javascript" src="js/cms_script.js"></script>
        </head>
        <body>
            <section>
                <header></header>
                <article>               
                    <div id="cms" class="normal cms_highlight">
                        
                        <h1 id="title"></h1>
                        <p id="content"></p>
                    </div>
                    <div id="debug_message"></div>
                    <button id="save">SAVE</button>
                </article>
                <footer></footer>
            </section>
        </body>
    </html>
    my jQuery file
    cms_script.js
    PHP Code:
    $(document).ready(function() {
        var 
    = new Date();
        
        $.
    ajax({
            
    url'data.php?='+d.getTime(),
            
    timeout5000,
            
    cachefalse,
            
    dataType"json",
            
    success: function(info) {

                var 
    id info.id;
                var 
    title info.title;
                var 
    content info.content;

                
                $(
    "h1[id=title]").append(title);
                $(
    "p[id=content]").append(content);


            },
            
    error: function(requeststatuserror) {
                
    alert(status ", " error);
            }
        });

        $(
    "#title").attr("contentEditable"true);
        $(
    "#content").attr("contentEditable"true);

        $(
    "#title").fadeIn(3000);
        $(
    "#content").fadeIn(3000);



        $(
    "#save").click(saveFCN);

    }); 
    // ready


    function saveFCN(evt) {

        var 
    title = $("#title").html();
        var 
    content = $("p[id=content]").html();
        
        $.
    ajax(
                {
                    
    url'save_data.php',                           
                    
    type"POST",
                    
    cachefalse,
                    
    data: {titletitle,
                        
    contentcontent, },
                    
    success: function(data) {
                        $(
    "#debug_message").html("<p>saved file</p>");
                    },
                    
    failure: function() {
                        $(
    "#debug_message").html(
                                
    "An error has occured trying to save the file");
                    }
                });
    }
    //    $.getJSON("data.php", function(info) { // Load data:
    //
    //
    //        var id = info.id;
    //        var title = info.title;
    //        var content = info.content;
    //
    //
    //        $("h1[id=title]").append(title);
    //        $("p[id=content]").append(content);
    //
    //    }); //getJSON 
    data.php
    PHP Code:
    <?php

    require('includes/utilities.inc.php');

    $page_id $_SESSION['edit_id'];
    // Validate the page ID:
    if (!isset($page_id) || !filter_var($page_idFILTER_VALIDATE_INT, array('min_range' => 1))) {
        throw new 
    Exception('An invalid page ID was provided to this page.');
    }
    $e = array();

    $setPage = new ReadPage();

    if (isset(
    $page_id)) {

        try {
            
    $query 'SELECT  id, title, content FROM pages WHERE id=:id';
            
    $stmt $pdo->prepare($query);
            
    $result $stmt->execute(array(':id' => htmlspecialchars($page_id)));

            
    // If the query ran OK, fetch the record into an object:
            
    if ($result) {

                
    $stmt->setFetchMode(PDO::FETCH_CLASS'Page');
                
    $page $stmt->fetch();

                
    $e['id'] = $page->getId();
                
    $e['title'] = $page->getTitle();
                
    $e['content'] = html_entity_decode($page->getContent());
            } else {
                throw new 
    Exception('An invalid page ID was provided to this page');
            }
        } catch (
    Exception $e) { // Catch generic exceptions
            
    include('views/error.html');
        }
    }
    print 
    json_encode($e);
    save_data.php
    PHP Code:
    <?php
    require('includes/utilities.inc.php');

    $id $_SESSION['edit_id'];
    $title htmlspecialchars(strip_tags($_POST['title']));
    $content htmlspecialchars($_POST['content']);

    // Update the edited text:     
    $query 'UPDATE  pages SET title=:title, content=:content, dateUpdated=NOW() WHERE id=:id';

    // Prepare the Statement:
    $stmt $pdo->prepare($query);

    // execute the statement:
    $show_details $stmt->execute(array('title' => $title':content' => $content':id' => $id));
    ?>
    I think it has something to do with the way Internet Explorer handles the cache, but every Google search I done the solution doesn't solve the problem. Sorry for the long code, but I think the problem is either in cms_script.js or data.php code.

    Thanks John
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,248
    Rep Power
    9400
    Crashes IE how? "IE has stopped responding"? A freeze?
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Burb of Detroit, Michigan
    Posts
    92
    Rep Power
    78
    Originally Posted by requinix
    Crashes IE how? "IE has stopped responding"? A freeze?
    It brings in the data (displays it) and it looks like it is going to work, but then it pops up -

    Internet Explorer has stopped working

    A problem caused the program to stop working correctly.
    Windows will close the program and notify you if a solution is available.


    The strange thing is that I have to close that message twice in order to close internet explorer.
  6. #4
  7. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by Strider64
    Internet Explorer has stopped working

    A problem caused the program to stop working correctly.
    Windows will close the program and notify you if a solution is available.
    I don't really have anything productive to say but I wanted to take a moment to pat you on the back for this accomplishment. I was starting to get worried that Microsoft was getting its crap together with IE. Close one.

    Comments on this post

    • Strider64 agrees : I think I just going to continue on, it might just be my local server causing the problem with MicroSilly.
    LinkedIn: Dave Mittner
  8. #5
  9. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,248
    Rep Power
    9400
    Originally Posted by Strider64
    The strange thing is that I have to close that message twice in order to close internet explorer.
    The first dialog is about looking for solutions to the problem, the second dialog is actually about automatically re-launching IE. Given a few seconds that second dialog should (it doesn't always) go away and restart IE for you.

    I'm figuring the Javascript forum is the best place to go from here. It doesn't sound like a PHP thing.
    What would be good to know is at what point IE crashes. Is it before you do anything on the page? When you try to trigger the AJAX? If that, take a look at your server access log: does it crash before or after the AJAX and PHP execute?
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Burb of Detroit, Michigan
    Posts
    92
    Rep Power
    78
    Thanks, I'm checking into the access log right now, it seems like my editPage.html page is attempting to load twice, making me to believe it has something to do with the JavaScript file and the cache as my Google search suggests. I tried to have no cache as the some of the solutions suggests, but to no avail. I guess I will do some more searching unless someone here might have a possible solution.

IMN logo majestic logo threadwatch logo seochat tools logo