2

I've got a page with a preview image on it, and when you click the preview image, JQuery replaces it with a Java applet using the ajax load() function. The applet comes up alright (it's netlogo) and seems to find the .nlogo file it's looking for.

This .nlogo filename is passed to the applet with a <param> tag. The applet is generic, and it will load any .nlogo file and run it just like the NetLogo desktop application.

It doesn't display anything however. I know it's finding the file, because when I pass it a bad filename, it throws an error, and right now it's not throwing one.

It works fine if the code is just placed in the html normally, but when it is loaded with ajax the applet does not initialize correctly.

I'm guessing that the applet is waiting for some kind of page-finished-loading event that's not ever going to happen. Is there any way I can fake that message?

The code is distributed all over the place but here are the relevant parts

The div I'm messing with

    <div id="previewDiv">
        Click the image to run the netlogo applet in your browser.<br>
        <img id="previewImage" src='<?php echo($modelPath . $previewFile); ?>' style="margin: 8px;" />
    </div>

The JQuery that replaces the preview image with the applet

$(document).ready(function(){
    $("#previewImage").click(function(){
        $("#previewDiv").load("appletcode.php?mid=<?php echo $mid; ?>");
    });
});

The applet code that get's sent down for the ajax request

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
include "library.php";
connectdb();

$mid = mysql_real_escape_string($_GET['mid']);
$sql = "SELECT * FROM models WHERE modelId=$mid;";
$result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
$row = mysql_fetch_array($result);

$version            = $row['netlogoVersionStr'];
$nlogocode          = $row['netlogoFile'];
$appletWidth        = $row['appletWidth'];
$appletHeight       = $row['appletHeight'];

$modelPath = "/complexityexplorer/netlogo/userfiles/$mid/";
$nlogoFilePath = $modelPath . rawurlencode($nlogocode);

?>


<applet code="org.nlogo.lite.Applet"
    archive="/complexityexplorer/netlogo/<?php echo rawurlencode($version) ?>/NetLogoLite.jar"
    width="<?php echo $appletWidth ?>" height="<?php echo $appletHeight ?>">
    <param name="DefaultModel"
        value="<?php echo $nlogoFilePath ?>">
    <param name="java_arguments"
        value="-Djnlp.packEnabled=true">
</applet>

God I hope someone has a shred of knowledge about this :/


Your expression is correct, but you should be using preg_match_all() instead to retrieve all matches. Here's a working example of what that would look like:

$s = 'This is a {demo} phrase made for {test}';

if (preg_match_all('/{([^}]*)}/', $s, $matches)) {
        echo join("\n", $matches[1]);
}

To also capture the positions of each match, you can pass PREG_OFFSET_CAPTURE as the fourth parameter to preg_match_all. To use that, you can use the following example:

if (preg_match_all('/{([^}]*)}/', $s, $matches, PREG_OFFSET_CAPTURE)) {
        foreach ($matches[1] as $match) {
            echo "{$match[0]} occurs at position {$match[1]}\n";
        }
}
4

0 に答える 0