PHP 到 jqueryDialog() 交互问题。

发布于 2024-12-26 00:43:45 字数 1521 浏览 1 评论 0原文

我有一个 html 按钮:

<button id="monitor" onclick="startMonitor('<?php echo $result_cameras[$i]["camera_hash"]; ?>', '<?php echo $result_cameras[$i]["camera_name"]; ?>', '<?php echo $camera_quality_flash; ?>');">Monitor</button>

这将加载 flash 内容:

<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
<script type="text/javascript">
var js = jQuery.noConflict();

var startMonitor = function(cameraHash, cameraName, cameraFlashQuality) {
var url = ['flash/app.php?user=<?php echo $id_hash; ?>', 'camera=' + cameraHash, 'name=' + encodeURIComponent(cameraName), 'quality=' + cameraFlashQuality].join('&');
js('<div></div>').load(url, function() {
    js(this).dialog();
});
};

我想使用 jquery 对话框打开此内容。传入的所有内容似乎都很完美(根据 firebug 的 GET 响应),但我仍然收到 jquery 错误。

缺少; before statements jquery.js line 612

我做错了什么?我什至不知道如何调试这个。提前致谢。

编辑: Firebug 将 GET 报告为: http://myurl.com/flash/app.php?user=dee8c751cfdd2b5fb8194a3a9bac12044621df3d&camera=8f753c6bb3a8d9852a220abff0ed0d7686563007&name=test22&quality=0。我期望这些值。

如果我将此 url 粘贴到浏览器中,Flash 应用程序将按预期在浏览器中启动,但显然不会出现 jquery 对话框。我的 jquery 代码一定有问题吗?

I have an html button:

<button id="monitor" onclick="startMonitor('<?php echo $result_cameras[$i]["camera_hash"]; ?>', '<?php echo $result_cameras[$i]["camera_name"]; ?>', '<?php echo $camera_quality_flash; ?>');">Monitor</button>

This would load flash content:

<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
<script type="text/javascript">
var js = jQuery.noConflict();

var startMonitor = function(cameraHash, cameraName, cameraFlashQuality) {
var url = ['flash/app.php?user=<?php echo $id_hash; ?>', 'camera=' + cameraHash, 'name=' + encodeURIComponent(cameraName), 'quality=' + cameraFlashQuality].join('&');
js('<div></div>').load(url, function() {
    js(this).dialog();
});
};

I want to use the jquery dialog to open this content. Everything passed in seems to be perfect (according to the GET response from firebug) but I still get a jquery error.

missing ; before statement jquery.js line 612

What am I doing wrong? I'm not even sure how to debug this. Thanks in advance.

EDIT:
Firebug reports the GET as: http://myurl.com/flash/app.php?user=dee8c751cfdd2b5fb8194a3a9bac12044621df3d&camera=8f753c6bb3a8d9852a220abff0ed0d7686563007&name=test22&quality=0. I expect these values.

If I paste this url into my browser the flash app starts in the browser as expected but not with the jquery dialog obviously. Must be something wrong with my jquery code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

通知家属抬走 2025-01-02 00:43:45

(删除了不正确的答案。)


编辑:

最初,我将 jquery.js 误解为您创建的文件,而不是真正的 jquery。测试代码后,我发现您发送的数据可能有问题。您能否发布包含 $result_cameras[$i]["camera_hash"]$result_cameras[$i]["camera_name"]数据的示例$camera_quality_flash$id_hash?另外,结果的 url 值是多少?


解决方案:

按钮提交表单,页面正在重新加载。该对话框显示,但页面立即重新加载,所以看起来好像从来没有对话框。为了防止这种行为,按钮的 click() 函数必须返回 false (如果没有返回值,则将其视为 true > 结果)。

此解决方案的注释:

  1. 依赖于存在的对象,因此我将所有内容移至 ready() 事件内。
  2. 假设这是循环内的众多按钮之一(由于 PHP 代码中的 $i 变量),因此数据位于按钮的属性中。
  3. 由于可能有多个具有相同功能的按钮,因此将其推广为多个按钮。
  4. jQuery 加载命令(参见 http://api.jquery.com/load/ )需要 3 个参数:
    • 网址
    • 一些数据
    • 加载返回时的回调函数(如果仅提供 2 个参数,则假定第二个参数为回调函数)。回调参数为:
      • responseText,从服务器返回的 HTML
      • textStatus,状态消息
      • XMLHttpRequest,请求接口,可用于查看有关请求的各种信息(参见http://www.w3.org/TR/XMLHttpRequest/)

) HTML 测试文件:

<html>
<head>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
</head>
<body>
<form>
    <?php 
        $i = 0;
        $result_cameras = array(array("camera_hash" => "test1", "camera_name" => "test2"));
        $camera_quality_flash = 1;
        $id_hash = "hashish";

        echo '<button id="monitor1" class="monitor" camHash="' . $result_cameras[$i]["camera_hash"] . '" camName="' . $result_cameras[$i]["camera_name"] . '" camQual="' . $camera_quality_flash . '" >Monitor 1</button>';
        echo '<button id="monitor2" class="monitor" camHash="' . $result_cameras[$i]["camera_hash"] . '-2" camName="' . $result_cameras[$i]["camera_name"] . '-2" camQual="' . $camera_quality_flash . '-2" >Monitor 2</button>';
    ?>
    <div class="tester">TEST DIV</div>
</form>
</body>

<script type="text/javascript">
    var js = jQuery.noConflict();
    js(document).ready(function(){

        var monitor = js(".monitor");
        //alert(monitor[1]);

        monitor.each(
            function(i){ 
                js(this).click(
                    function(){
                        //alert(js(this).attr('camHash'));
                        startMonitor( 
                            js(this).attr('camHash'),
                            js(this).attr('camName'),
                            js(this).attr('camQual')
                        ); 
                        return false;
                    }
                );
            }
        );

        var startMonitor = function(cameraHash, cameraName, cameraFlashQuality) {

            var url = [
                    'flash/app.php?user=<?php echo $id_hash; ?>', 
                    'camera=' + cameraHash, 
                    'name=' + encodeURIComponent(cameraName), 
                    'quality=' + cameraFlashQuality
                ].join('&');

            js('<div>TEST DIV 2</div>').load(url
                , function(response, status, xhr) {
                    js('.tester').text( "<div>xhr: <br />"
                        + xhr.status + "<br />"
                        + xhr.statusText + "<br />"
                        + xhr.getAllResponseHeaders() + "<br />"
                        + xhr.responseText + "<br />"
                        + xhr.responseXML + "<br />"
                        + "</div>"
                    );
//                  js(this).dialog();
                }
            );
        };
    });
</script>

</html>

(Incorrect answer removed.)


Edit:

Initially, I misinterpreted the jquery.js as a file you created, rather than the real jquery. After testing out the code, I can see that the data that you are sending may be the problem. Can you post a sample with the data for $result_cameras[$i]["camera_hash"], $result_cameras[$i]["camera_name"],$camera_quality_flash, and $id_hash? Also, what is the value for url that results?


Solution:

The button submits the form, and the page is reloading. The dialog shows, but then the page is immediately reloaded, so it seems like there never was a dialog. In order to prevent this behavior, the button's click() function has to return false (if no value is return, it is treated as a true result).

Notes on this solution:

  1. Relies on the objects being in existence, so I moved everything inside a ready() event.
  2. Assumes this one of many buttons inside a loop (because of the $i variable in the PHP code), so the data is in the attributes of the button.
  3. Since there may be several buttons with the same functionality, it is generalized for multiples.
  4. The jQuery load command (cf., http://api.jquery.com/load/ ) takes 3 paramenters:
    • the url
    • some data
    • a callback function for when the load returns (if you only provide 2 parameters, the second one is assumed to be the callback function). The callback parameters are:
      • responseText, the HTML returned from the server
      • textStatus, a status message
      • XMLHttpRequest, the request interface, which can be used to see various info about the request (cf., http://www.w3.org/TR/XMLHttpRequest/)

The HTML test file:

<html>
<head>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
</head>
<body>
<form>
    <?php 
        $i = 0;
        $result_cameras = array(array("camera_hash" => "test1", "camera_name" => "test2"));
        $camera_quality_flash = 1;
        $id_hash = "hashish";

        echo '<button id="monitor1" class="monitor" camHash="' . $result_cameras[$i]["camera_hash"] . '" camName="' . $result_cameras[$i]["camera_name"] . '" camQual="' . $camera_quality_flash . '" >Monitor 1</button>';
        echo '<button id="monitor2" class="monitor" camHash="' . $result_cameras[$i]["camera_hash"] . '-2" camName="' . $result_cameras[$i]["camera_name"] . '-2" camQual="' . $camera_quality_flash . '-2" >Monitor 2</button>';
    ?>
    <div class="tester">TEST DIV</div>
</form>
</body>

<script type="text/javascript">
    var js = jQuery.noConflict();
    js(document).ready(function(){

        var monitor = js(".monitor");
        //alert(monitor[1]);

        monitor.each(
            function(i){ 
                js(this).click(
                    function(){
                        //alert(js(this).attr('camHash'));
                        startMonitor( 
                            js(this).attr('camHash'),
                            js(this).attr('camName'),
                            js(this).attr('camQual')
                        ); 
                        return false;
                    }
                );
            }
        );

        var startMonitor = function(cameraHash, cameraName, cameraFlashQuality) {

            var url = [
                    'flash/app.php?user=<?php echo $id_hash; ?>', 
                    'camera=' + cameraHash, 
                    'name=' + encodeURIComponent(cameraName), 
                    'quality=' + cameraFlashQuality
                ].join('&');

            js('<div>TEST DIV 2</div>').load(url
                , function(response, status, xhr) {
                    js('.tester').text( "<div>xhr: <br />"
                        + xhr.status + "<br />"
                        + xhr.statusText + "<br />"
                        + xhr.getAllResponseHeaders() + "<br />"
                        + xhr.responseText + "<br />"
                        + xhr.responseXML + "<br />"
                        + "</div>"
                    );
//                  js(this).dialog();
                }
            );
        };
    });
</script>

</html>
瞳孔里扚悲伤 2025-01-02 00:43:45

您能确认您显示的返回内容是实际内容吗?
如果是这样,那就不对了,因为它包含 PHP 标签。

但是,如果这是从您的服务器端代码复制的,您能否发布从服务器获得的实际响应,因为这很可能是您的问题所在。

谢谢

Can you confirm that the return content you show is the actual content?
If so, it is not right because it contains PHP tags.

If however this is copied from your server-side code, can you please post the ACTUAL response you get from the server as this is most probably where your problem is.

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文