I have an html button:
我有一个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>
This would load flash content:
这将加载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();
});
};
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.
我想使用jquery对话框打开这个内容。所有传入的内容看起来都很完美(根据来自firebug的GET响应),但我仍然会得到一个jquery错误。
missing ; before statement jquery.js line 612
失踪的;jquery之前声明。js第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.
编辑:Firebug报告如下:http://myurl.com/flash/app.php?我希望这些价值观。
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?
如果我将这个url粘贴到我的浏览器中flash应用程序会按预期在浏览器中启动,但显然不会使用jquery对话框。我的jquery代码一定有问题吧?
2 个解决方案
#1
7
(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?
最初,我误解了jquery。js作为您创建的文件,而不是真正的jquery。在测试代码之后,我可以看到您发送的数据可能是问题所在。你能将$result_camera [$i]["camera_hash"]、$result_camera [$i]["camera_name"]、$camera_quality_flash和$id_hash的数据发布一个示例吗?同样,url的值是什么?
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).
按钮提交表单,页面正在重新加载。对话框会显示出来,但随后页面会立即重新加载,因此看起来似乎从来没有对话框。为了防止这种行为,按钮的click()函数必须返回false(如果没有返回值,则将其视为真实结果)。
Notes on this solution:
笔记这个解决方案:
- Relies on the objects being in existence, so I moved everything inside a
ready()
event. - 依赖于存在的对象,所以我将所有内容移动到ready()事件中。
- 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. - 假设循环中有许多按钮(因为PHP代码中的$i变量),因此数据位于按钮的属性中。
- Since there may be several buttons with the same functionality, it is generalized for multiples.
- 因为可能有几个按钮具有相同的功能,所以它对于多个按钮是通用的。
- The jQuery load command (cf., http://api.jquery.com/load/ ) takes 3 paramenters:
- the url
- 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
- 从服务器返回的HTML
- textStatus, a status message
- textStatus状态消息
- XMLHttpRequest, the request interface, which can be used to see various info about the request (cf., http://www.w3.org/TR/XMLHttpRequest/)
- XMLHttpRequest是请求接口,可以用来查看关于请求的各种信息(cf., http://www.w3.org/TR/XMLHttpRequest/)
- 当负载返回时的回调函数(如果您只提供2个参数,则假定第二个参数是回调函数)。回调参数是:responseText,从服务器textStatus返回的HTML,一个状态消息XMLHttpRequest,请求接口,可以用来查看关于请求的各种信息(cf., http://www.w3.org/TR/XMLHttpRequest/)
- jQuery load命令(cf., http://api.jquery.com/load/)接受3个参数:url作为加载返回时的回调函数(如果只提供2个参数,则假定第二个参数为回调函数)。回调参数是:responseText,从服务器textStatus返回的HTML,一个状态消息XMLHttpRequest,请求接口,可以用来查看关于请求的各种信息(cf., http://www.w3.org/TR/XMLHttpRequest/)
The HTML test file:
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>
#2
0
Can you confirm that the return content you show is the actual content? If so, it is not right because it contains PHP tags.
你能确认你显示的返回内容是真实的内容吗?如果是,那就不对了,因为它包含PHP标记。
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
谢谢
#1
7
(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?
最初,我误解了jquery。js作为您创建的文件,而不是真正的jquery。在测试代码之后,我可以看到您发送的数据可能是问题所在。你能将$result_camera [$i]["camera_hash"]、$result_camera [$i]["camera_name"]、$camera_quality_flash和$id_hash的数据发布一个示例吗?同样,url的值是什么?
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).
按钮提交表单,页面正在重新加载。对话框会显示出来,但随后页面会立即重新加载,因此看起来似乎从来没有对话框。为了防止这种行为,按钮的click()函数必须返回false(如果没有返回值,则将其视为真实结果)。
Notes on this solution:
笔记这个解决方案:
- Relies on the objects being in existence, so I moved everything inside a
ready()
event. - 依赖于存在的对象,所以我将所有内容移动到ready()事件中。
- 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. - 假设循环中有许多按钮(因为PHP代码中的$i变量),因此数据位于按钮的属性中。
- Since there may be several buttons with the same functionality, it is generalized for multiples.
- 因为可能有几个按钮具有相同的功能,所以它对于多个按钮是通用的。
- The jQuery load command (cf., http://api.jquery.com/load/ ) takes 3 paramenters:
- the url
- 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
- 从服务器返回的HTML
- textStatus, a status message
- textStatus状态消息
- XMLHttpRequest, the request interface, which can be used to see various info about the request (cf., http://www.w3.org/TR/XMLHttpRequest/)
- XMLHttpRequest是请求接口,可以用来查看关于请求的各种信息(cf., http://www.w3.org/TR/XMLHttpRequest/)
- 当负载返回时的回调函数(如果您只提供2个参数,则假定第二个参数是回调函数)。回调参数是:responseText,从服务器textStatus返回的HTML,一个状态消息XMLHttpRequest,请求接口,可以用来查看关于请求的各种信息(cf., http://www.w3.org/TR/XMLHttpRequest/)
- jQuery load命令(cf., http://api.jquery.com/load/)接受3个参数:url作为加载返回时的回调函数(如果只提供2个参数,则假定第二个参数为回调函数)。回调参数是:responseText,从服务器textStatus返回的HTML,一个状态消息XMLHttpRequest,请求接口,可以用来查看关于请求的各种信息(cf., http://www.w3.org/TR/XMLHttpRequest/)
The HTML test file:
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>
#2
0
Can you confirm that the return content you show is the actual content? If so, it is not right because it contains PHP tags.
你能确认你显示的返回内容是真实的内容吗?如果是,那就不对了,因为它包含PHP标记。
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
谢谢