Heim  >  Artikel  >  Backend-Entwicklung  >  js怎么将变量传递给php,或者说js怎么触发php函数

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

WBOY
WBOYOriginal
2016-06-23 13:47:36786Durchsuche

在页面A.php中,要统计页面中各元素(图片/链接)点击量,并将点击量存储起来。

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

请问,用什么方法,能够在点击(图片/链接)时,触发php的反应~~


回复讨论(解决方案)

使用 Ajax

用ajax,或者curl.
最快的办法就是用jquery的$.ajax方法.

用ajax,或者curl.
最快的办法就是用jquery的$.ajax方法.


--------------------------------------------------------------

使用 Ajax


---------------------------------------------------------------
请问,可以用js的方法调用Ajax吗?

你多看看基础的书吧。或者下载些chm文档看看关于jquery.ajax那章

你多看看基础的书吧。或者下载些chm文档看看关于jquery.ajax那章


------------------------------------------------------------------------------------------------------
来这不就是为了速成么?

//给你个demo
//需要下载个jquery.js
$.ajax({
   type: "POST", //请求方式
   url: "some.php",//请求文件
   data: "name=John&location=Boston",//传输的参数
   success: function(msg){
     alert( "Data Saved: " + msg );//返回的结果
   }
});
//可以把ajax看做一个表单请求。但可以实时返回结果

//给你个demo
//需要下载个jquery.js
$.ajax({
   type: "POST", //请求方式
   url: "some.php",//请求文件
   data: "name=John&location=Boston",//传输的参数
   success: function(msg){
     alert( "Data Saved: " + msg );//返回的结果
   }
});
//可以把ajax看做一个表单请求。但可以实时返回结果


-------------------------------------------------------------------------------
然后在some.php中,通过$_POST['name']获取John?

//给你个demo
//需要下载个jquery.js
$.ajax({
   type: "POST", //请求方式
   url: "some.php",//请求文件
   data: "name=John&location=Boston",//传输的参数
   success: function(msg){
     alert( "Data Saved: " + msg );//返回的结果
   }
});
//可以把ajax看做一个表单请求。但可以实时返回结果


-----------------------------------------------------------------------------
也不对,php应该获得的就是个字符串吧?
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn