[英]What is the Problem with this kind of Data for Javascript and PHP
I have a Html table which consists of the Data Generated through serverside php .It consists of many rows.Each Row Contains One Button Called "Approve" . 我有一个Html表,该表包含通过服务器端php生成的数据。它包含许多行。每行包含一个称为“批准”的按钮。 when clicked on "Approve" it goes to one php file and does its DB transcations 当单击“批准”时,它将转到一个php文件并执行其数据库事务处理
Here is what i have Code for "Approve button " in php 这是我在php中“批准按钮”的代码
$cntrl = "<input name=btn1 type=button id=btn1 value=Approve onClick=\"callApprove('".$row['val1']."','".$row['val2']."');\"";
Here is the JS Function called when clicked on "Approve". 这是单击“批准”时调用的JS函数。
function callApprove(val1,val2){
var url = 'approve.php?id=<?php echo $_REQUEST['var3'];?>¶m1='+val1+'¶m2='+val2;
window.open(url)
}
Now Here my Problem is when i have the data as "ABC6252756/ A#1829533" .when i have this kind of data val2 i not being passed to approve.php where as when we have this kind of data "ABC07- USVDL2" it value is being passed succesfully. 现在,这里的问题是当我将数据作为“ ABC6252756 / A#1829533”时。当我将这种数据val2传递给approve.php时,就像当我们拥有这种数据“ ABC07-USVDL2”时一样值已成功传递。 Do we have any kind of problem with the (/,#) characters . (/,#)字符有什么问题吗? For Safe Side i have put the alert for the val2 for ("ABC6252756/ A#1829533") this data It came up succesfully . 为了安全起见,我已为(“ ABC6252756 / A#1829533”)此数据输入了val2警报。 What might be the problem? 可能是什么问题?
You are referencing val1
and val2
inside callApprove
but don't include the code where you set them. 您在callApprove
中引用了val1
和val2
, callApprove
在设置它们的地方包含代码。 Also, you call callApprove with arguments inside your onClick function, but the definition has no arguments ( function callApprove
) -- perhaps that's where you mean to initialize them? 另外,您可以在onClick函数中使用参数调用callApprove,但是定义中没有参数( function callApprove
),也许这就是初始化它们的目的?
I think the hash is your problem. 我认为哈希是您的问题。 The hash symbol , #
, has a specific meaning in a URL and that meaning is a client-side issue only; 哈希符号 #
在URL中具有特定含义,并且该含义仅是客户端方面的问题; since it is a client/browser issue, the hash and whatever comes after it won't be sent to the server. 由于这是客户端/浏览器问题,因此哈希以及哈希之后的所有内容都不会发送到服务器。 When you insert "ABC6252756/ A#1829533" into the URL, the browser will remove "#1829533" and everything that comes after it before sending the URL to the server. 当您在URL中插入“ ABC6252756 / A#1829533”时,浏览器将在将URL发送到服务器之前删除“#1829533” 及其后的所有内容 。
The solution is to properly URL-encode each part of your query string. 解决方案是对查询字符串的每个部分进行正确的URL编码。 You'd use encodeURIComponent
in JavaScript or, I think, urlencode
in PHP. 您可能会在JavaScript中使用encodeURIComponent
,或者在PHP中使用urlencode
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.