Tengo un problema en mi proyecto. Me gustaría acceder a mi función cuando termine el iframe, pero intento buscar cómo puedo hacer esto, pero todas las soluciones no funcionan, no sé por qué. Mi proyecto tiene plantillas de la aplicación web Asp.Net (.NET Framework).
Script js, cuando cree un iframe e "intente" conectarse a mi función en WebForm1.aspx.cs:
<script> const tag = document.createElement("script"); tag.id = "iframe-demo"; tag.src = "https://www.youtube.com/iframe_api"; const [firstScriptTag] = document.getElementsByTagName("script"); firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); let player; window.onYouTubeIframeAPIReady = () => { player = new window.YT.Player("player", { width: 500, height: 500, videoId: "M7lc1UVf-VE", events: { onStateChange: window.onPlayerStateChange } }); }; window.onPlayerStateChange = (event) => { if (event.data === 0) { jQuery.ajax({/* * */ method: "POST", url: "/WebForm1.aspx/returnid", error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(textStatus); }, success: function (result) { console.log("success"); } }); } }; </script>Código de WebForm1.aspx.cs:
[WebMethod]//[WebMethod()] public static string returnid(string subject, string message, string messageId, string pupilId) { Console.WriteLine("testar"); return "";//https://www.youtube.com/watch?v=8elyZ6aGgZY } Intento usar $.ajax, ajax, $Jquery allí * y no funciona.
Tienes que importar jQuery, agrega esto dentro de la etiqueta del encabezado:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>