简体   繁体   中英

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" . when clicked on "Approve" it goes to one php file and does its DB transcations

Here is what i have Code for "Approve button " in 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".

function  callApprove(val1,val2){
 var url = 'approve.php?id=<?php echo $_REQUEST['var3'];?>&param1='+val1+'&param2='+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. 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 . What might be the problem?

You are referencing val1 and val2 inside callApprove but don't include the code where you set them. 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?

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; 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.

The solution is to properly URL-encode each part of your query string. You'd use encodeURIComponent in JavaScript or, I think, urlencode in PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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