(Invalid response deleted.)
Edit:
At first, I misinterpreted jquery.js as the file you created, not the real jquery. After checking the code, I see that the data you send may be a problem. Can you place a sample with 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?
Decision:
The button submits the form, and the page reloads. The dialog box shows, but then the page immediately reloads, so it seems like there has never been a dialog. To prevent this behavior, the click() function must return false (if the value is not returned, it is considered as the result of true ).
Notes to this decision:
- It relies on existing objects, so I moved everything inside the
ready() event. - This is supposed to be one of many buttons inside the loop (due to the
$i variable in PHP code), so the data is in the button attributes. - Since there may be several buttons with the same functionality, they are generalized for brevity.
- The jQuery download command (cf., http://api.jquery.com/load/ ) accepts 3 paragraphs:
- URL
- some data
- callback function to return the load (if you provide only 2 parameters, the second is considered a callback function). Callback Options:
- responseText, HTML returned from the server
- textStatus status message
- XMLHttpRequest, a request interface that can be used to view various information about the request (see http://www.w3.org/TR/XMLHttpRequest/ )
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>
source share