Home > Backend Development > PHP Tutorial > js如何将变量传递给php,或者说js如何触发php函数

js如何将变量传递给php,或者说js如何触发php函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:08:11
Original
965 people have browsed it

js怎么将变量传递给php,或者说js怎么触发php函数
在页面A.php中,要统计页面中各元素(图片/链接)点击量,并将点击量存储起来。

目前是php跟数据库进行交互的,所以希望用户点击(图片/链接)后,php能有所反应,去更新数据库中相应表。

请问,用什么方法,能够在点击(图片/链接)时,触发php的反应~~
------解决思路----------------------
使用 Ajax
------解决思路----------------------
用ajax,或者curl.
最快的办法就是用jquery的$.ajax方法.
------解决思路----------------------
//给你个demo
//需要下载个jquery.js
$.ajax({
   type: "POST", //请求方式
   url: "some.php",//请求文件
   data: "name=John&location=Boston",//传输的参数
   success: function(msg){
     alert( "Data Saved: " + msg );//返回的结果
   }
});
//可以把ajax看做一个表单请求。但可以实时返回结果

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template