Problems with PHP interaction with 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 will 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 went seems to be perfect (according to the GET answer from firebug), but I'm still getting 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 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 application runs in the browser as expected, but not with the jquery dialog. There must be something wrong with my jquery code?

+4
source share
2 answers

(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> 
+7
source

Can you confirm that the returned content that you display is the actual content? If so, this is not true because it contains PHP tags.

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

thanks

0
source

Source: https://habr.com/ru/post/1390146/


All Articles