I want store clickede_id
value into $id2[]
give me some suggestions and also suggest some advance details
我希望商店clickede_id值进入$ id2 []给我一些建议,并提出一些预先详细信息
function yes(clicked_id)
{
var it1=clicked_id;
alert(it1);
var tt1=1;
var tt2= "<?php echo($id2[var it1]); ?>";
//var tt2=document.getElementById("idcheck").value;
alert(tt2);
var tt3=document.getElementById("idcheck1").value;
//alert(tt3);
}
2 个解决方案
#1
0
When you develop a web application, you are creating tools to let client and server communicates (over the HTTP protocol). This communication is based on Requests and Responses.
在开发Web应用程序时,您正在创建允许客户端和服务器通过HTTP协议进行通信的工具。此通信基于请求和响应。
The client send request to server and the server responds with a reponse. In your case, you choosed PHP as the server-side language that will create your responses as answers to client request. Thes responses are HTML (+ javascript). Anyways, the reponses are static stuff to be interpredted by the client.
客户端向服务器发送请求,服务器响应响应。在您的情况下,您选择PHP作为服务器端语言,它将创建您的响应作为客户端请求的答案。这些回复是HTML(+ javascript)。无论如何,响应是由客户端传播的静态内容。
So the code you have sent is seen by the browser as:
因此,您发送的代码被浏览器视为:
function yes(clicked_id)
{
var it1=clicked_id;
alert(it1);
var tt1=1;
var tt2= 3; // or whatever value returned by php
var tt2=document.getElementById("idcheck").value;
var tt3=document.getElementById("idcheck1").value;
// ajax call here
}
When you say : store data from javascript to php (even if it doesnt look as a correct senetence), you mean sending data from client to server. It can be done via a classical Post request (via form submit with page refresh) or via ajax without page refresh.
当你说:将数据从javascript存储到php(即使它看起来不是正确的一样),你的意思是从客户端向服务器发送数据。它可以通过经典的Post请求(通过表单提交页面刷新)或通过ajax完成,无需页面刷新。
For ajax, please to check jQuery documentation for $.ajax
function (if you want to have a cross browser compatible solution), or XMLHTTPRequest
object if you want raw javascript and do the cross-browser compatibility yourself.
对于ajax,请检查$ .ajax函数的jQuery文档(如果你想要一个跨浏览器兼容的解决方案),或者如果你想要原始的javascript并且自己做跨浏览器兼容性的XMLHTTPRequest对象。
#2
0
PHP executes in the server and send the result to your browser to display. Your JS executes at this browser stage. What you need to understand is that PHP has already been finished it's execution when your JS gets a chance to execute. Trying to change something in PHP through the JS is trying to access the past.
PHP在服务器中执行并将结果发送到您的浏览器以显示。您的JS在此浏览器阶段执行。您需要了解的是,当您的JS有机会执行时,PHP已经完成了它的执行。试图通过JS改变PHP的东西是试图访问过去。
But, the good news is, that you can adopt a model where you feed your JS through the PHP script (look at this echo "<script>var s = 'from php'</script>"
) and JS feeds your NEXT php execution. You can use ajax or direct page calling for this.
但是,好消息是,你可以采用一个模型,通过PHP脚本为你的JS提供信息(看看这个echo“
Probably you should read this question: How to pass data from Javascript to PHP and vice versa?
您可能应该阅读这个问题:如何将数据从Javascript传递到PHP,反之亦然?
#1
0
When you develop a web application, you are creating tools to let client and server communicates (over the HTTP protocol). This communication is based on Requests and Responses.
在开发Web应用程序时,您正在创建允许客户端和服务器通过HTTP协议进行通信的工具。此通信基于请求和响应。
The client send request to server and the server responds with a reponse. In your case, you choosed PHP as the server-side language that will create your responses as answers to client request. Thes responses are HTML (+ javascript). Anyways, the reponses are static stuff to be interpredted by the client.
客户端向服务器发送请求,服务器响应响应。在您的情况下,您选择PHP作为服务器端语言,它将创建您的响应作为客户端请求的答案。这些回复是HTML(+ javascript)。无论如何,响应是由客户端传播的静态内容。
So the code you have sent is seen by the browser as:
因此,您发送的代码被浏览器视为:
function yes(clicked_id)
{
var it1=clicked_id;
alert(it1);
var tt1=1;
var tt2= 3; // or whatever value returned by php
var tt2=document.getElementById("idcheck").value;
var tt3=document.getElementById("idcheck1").value;
// ajax call here
}
When you say : store data from javascript to php (even if it doesnt look as a correct senetence), you mean sending data from client to server. It can be done via a classical Post request (via form submit with page refresh) or via ajax without page refresh.
当你说:将数据从javascript存储到php(即使它看起来不是正确的一样),你的意思是从客户端向服务器发送数据。它可以通过经典的Post请求(通过表单提交页面刷新)或通过ajax完成,无需页面刷新。
For ajax, please to check jQuery documentation for $.ajax
function (if you want to have a cross browser compatible solution), or XMLHTTPRequest
object if you want raw javascript and do the cross-browser compatibility yourself.
对于ajax,请检查$ .ajax函数的jQuery文档(如果你想要一个跨浏览器兼容的解决方案),或者如果你想要原始的javascript并且自己做跨浏览器兼容性的XMLHTTPRequest对象。
#2
0
PHP executes in the server and send the result to your browser to display. Your JS executes at this browser stage. What you need to understand is that PHP has already been finished it's execution when your JS gets a chance to execute. Trying to change something in PHP through the JS is trying to access the past.
PHP在服务器中执行并将结果发送到您的浏览器以显示。您的JS在此浏览器阶段执行。您需要了解的是,当您的JS有机会执行时,PHP已经完成了它的执行。试图通过JS改变PHP的东西是试图访问过去。
But, the good news is, that you can adopt a model where you feed your JS through the PHP script (look at this echo "<script>var s = 'from php'</script>"
) and JS feeds your NEXT php execution. You can use ajax or direct page calling for this.
但是,好消息是,你可以采用一个模型,通过PHP脚本为你的JS提供信息(看看这个echo“
Probably you should read this question: How to pass data from Javascript to PHP and vice versa?
您可能应该阅读这个问题:如何将数据从Javascript传递到PHP,反之亦然?