简体   繁体   English

如何从javaScript中的url(href链接)获取php变量,并在鼠标悬停时使用传递的php数据生成一个小的弹出窗口

[英]How to get php variable from url (href link) in javaScript and generate a small popup window on mouseover with passed php data

I am totally new to JavaScript or jQuery. 我对JavaScript或jQuery完全陌生。 Actually I am developing a web application under which I need to access some data in url format and I want to display a small popup window on mouseover event on this url and on occurrence of this event, url will pass three different php data IDs to javascript. 实际上,我正在开发一个Web应用程序,在该应用程序下,我需要以url格式访问一些数据,并且我想在此URL上发生mouseover事件时显示一个小的弹出窗口,并且在发生此事件时,URL会将三个不同的php数据ID传递给javascript 。 Then small popup window will get some related data from mysql with the help of those passed IDs. 然后,小的弹出窗口将在那些传递的ID的帮助下从mysql获取一些相关数据。

The answers to all of these questions are already here on SO. 所有这些问题的答案已经在SO上了。 Break your problem down into smaller steps and you will find it: 将您的问题分解为较小的步骤,您会发现:

The easiest solution is to use ajax. 最简单的解决方案是使用ajax。 Here is a sample implementation: 这是一个示例实现:

  1. The url link should contain the data you want to send to the server and would look like: url链接应包含您要发送到服务器的数据,如下所示:

     <a href="yourURL" onclick="sendURL2Srvr(this);">link text</a> 
  2. create a javascript section to receive the server response in a popup. 创建一个javascript部分,以在弹出窗口中接收服务器响应。 This should roughly look like: 大致如下所示:

     <script> http = false; if (window.ActiveXObject) { http = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest ) { http = new XMLHttpRequest(); } function sendURL2Srvr(elem) { http.abort(); http.onreadystatechange=function() { var popupW=window.createPopup(); if(http.readyState == 4) { if (http.status != 200) error('Something went wrong!'); else popupW.innerHTML=http.responseText; } } http.open("GET", elem.href, true); http.send(null); } </script> 
  3. It is up to the server to dissect the received REQUEST and send the data back. 由服务器决定接收到的REQUEST并将数据发送回去。 This now becomes a pure php question. 现在,这成为一个纯PHP问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM