473,473 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

calling js from php and returning value to php from js

omerbutt
638 Contributor
hi there i am making an application in which i have a drop down menu which onchange passes a value(this.value) to a js function which gets the value and
calls an ajax routine and passes that value to a php page and then takes back the response ,i have done it all but now i was trying to encrypt the information or the string or the value that is passed through the drop down menu and concatinated with the url and passed to that page and then on that page it would call the js function in php and pass that encoded string to an another decoding Javascript function and takes back the decoded string then run the query for the desired values and then response back but i am not doing it right i am pasting only the relevent js and php code here ,thanks for any help in advance.
function Pupu(val) is called onchange and passes the value to the getflds.php page,and function xor_str(url) id the encoding function that encodes the string
MAIN PAGE.PHP
Expand|Select|Wrap|Line Numbers
  1. function xor_str(url){
  2.     //var to_enc = document.forms['the_form'].elements["str"].value;
  3.     var to_enc = url;
  4.     //var xor_key=document.forms['the_form'].elements.xor_key.value
  5.     var xor_key=6;
  6.     var the_res="";//the result will be here
  7.     for(i=0;i<to_enc.length;++i){
  8.         the_res+=String.fromCharCode(xor_key^to_enc.charCodeAt(i));
  9.     }
  10.     //document.forms['the_form'].elements.res.value=the_res;
  11.     return the_res;
  12. }
  13.  
  14. function Pupu(val){    
  15.     if(val!="" && val!="none"){
  16.         var fobj=document.forms['Selfrm'];
  17.         var valar=val.split("|");
  18.         var cat_id=valar[0];
  19.         var prd_id=valar[1];
  20.         var rows=valar[2];
  21.         //alert(prd_id);
  22.         var prd_name=fobj.elements['prod'+rows].options[fobj.elements['prod'+rows].selectedIndex].text;
  23.         prd_name=stripper(prd_name);
  24.         var url="getflds.php?";
  25.         var cnct_str="cat_id="+cat_id+"&prd_id="+prd_id+"&prd_name="+prd_name+"&rows="+rows;
  26.         var dec_str=xor_str(cnct_str);
  27.         alert(dec_str);
  28.         var enc_str=decrypt_str(dec_str);
  29.         alert(enc_str);
  30.         return;
  31.         url=url+"str="+dec_str;
  32.         //alert(url);
  33.         //return;
  34.         xmlHttp=GetXmlHttpObject();
  35.         if(xmlHttp==null){
  36.             alert("Please Upgrade your browser to continue");
  37.         }else{
  38.             xmlHttp.onreadystatechange=stateFlds;
  39.             xmlHttp.open("GET",url,true);
  40.             xmlHttp.send(null);
  41.         }
  42.     }
  43. }
  44. function stateFlds(){
  45.     if(xmlHttp.readyState==4){
  46.         if(xmlHttp.status==200){
  47.             alert(xmlHttp.responseText);
  48.             //var a=xmlHttp.responseText;
  49.             //var pipe=a.split("^");
  50.             //var tab=pipe[0];
  51.             //var rows=pipe[1];
  52.             //alert(tab);
  53.             //document.getElementById('specs'+rows).innerHTML=tab;
  54.         }
  55.     }
  56. }
  57.  
  58.  
PAGE:GETFLDS.PHP
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $str=$_GET['str'];
  3. echo $str;
  4. echo "<script type='text/javascript' language='javascript'>decrypt_str(".$str.");</script>";
  5. ?>
  6. <script type="text/javascript" language="javascript">
  7.     function decrypt_str(){
  8.         alert("hi");
  9.         var to_dec=<?php echo $str;?>;
  10.         var dec_str;
  11.         document.forms['the_form'].elements.dec_res.value="";
  12.         var xor_key=6;
  13.         for(i=0;i<to_dec.length;i++){
  14.             dec_str+=String.fromCharCode(xor_key^to_dec.charCodeAt(i));
  15.         }
  16.         document.write(dec_str);
  17.     }
  18. </script>
  19.  
REGARDS,
OMER ASLAM
Jun 6 '08 #1
4 2383
dlite922
1,584 Recognized Expert Top Contributor
What in the world are you trying to do?

You used "and" 14 times.

Here's what i understood (miraculously)

1. You have a PHP program that returns a value to the page
2. That value is passed to a js function
3. This js function uses this variable somehow to call PHP again with AJAX.
4. ???
5. Profit!

(sorry last two were digg.com jokes)

But that's all I understood. May be bullet point or put some line breaks in your question so we can understand it.
Jun 6 '08 #2
Atli
5,058 Recognized Expert Expert
Hi.

I got to agree with the previous post. Line brakes and periods are your friends! :)

That said... what exactly is the problem?
You've tried to explain what it is that you are trying to do, but I fail to see why / how it is not working.
Jun 6 '08 #3
omerbutt
638 Contributor
What in the world are you trying to do?

You used "and" 14 times.

Here's what i understood (miraculously)

1. You have a PHP program that returns a value to the page
2. That value is passed to a js function
3. This js function uses this variable somehow to call PHP again with AJAX.
4. ???
5. Profit!

(sorry last two were digg.com jokes)

But that's all I understood. May be bullet point or put some line breaks in your question so we can understand it.
1st....i believe miracles do happen......thanks for tha concentration...:D...and excluding the last two DIGG JOKES you are not even right in the first three points not even near to what i am trying to do but lemme elaborate it again
NOW
  • the main thing i am tying to do is to encrypt a string in javascript
  • send it to a php page
  • and there after getting the encrypted string decode it again by calling a javascript function BUT through PHP cause i aint got any other option
the reason is that i am sending this value through an AJAX call.It means i will not land on that particular page,so that i would click any button and call that javascript function NEITHER can i have a "<BODY onload='JAVSCRIPT FUNCTION();'> TAG "
so that i may call that function onload .i have to do it this way .........SEQUENTIALLY STEPS AFTER STEPS ........THROUGH OUT IN PHP



i got to encrypt that string by calling a JS function through php and OF-COURSE
if i send i particular string to any function to get the results i need to pass it back too......WHATS WORRY IN IT .....dont you guys do like that [:O]
and when i got to do it i gotta do it ......if you can tell me my regards ,if you cant NO WORRIES I HAVE TO DO IT NO MATTER HOW,thanks for any help in advance
regards,
Omer Aslam.
Jun 7 '08 #4
Atli
5,058 Recognized Expert Expert
Ok. That's kind of odd... but ok.

Couldn't you just decode it after you get the result from the PHP script?
(I assume it is meant to do something more than you showed us. Otherwise it would be completely redundant)

If you do:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo "<script type=text/javascript>document.write("Hi");</script>";
  3. ?>
  4.  
And call that via AJAX, you won't just get "Hi", you will get the entire thing as a string. It won't be read as any form of markup or script, but simply as a string.

The only realistic option is to decode the string after you get it back from the AJAX request.
Either that or to make a PHP version of your decoding function and decode it within the PHP code before sending it.
Jun 7 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

30
by: Tim Marshall | last post by:
Here's the scenario, A2003, Jet back end, illustrated with some cut down code at the end of the post: A proc dims a snapshot recordset (dim rst as Dao.recordset) and opens it. There are several...
7
by: JJ | last post by:
Hi, I call a class in my windows service app and in that class I access a method that returns an OleDbReader. Now It does have records in the reader when I step through the method but when I...
1
by: Bern McCarty | last post by:
What do you make of this? I cannot tell for sure but it almost seems as the the transition thunk to get back from the native bool method to the managed caller is looking at eax and, if any bit is...
3
by: Mike | last post by:
Timeout Calling Web Service I am calling a .NET 1.1 web service from an aspx page. The web service can take several minutes to complete its tasks before returning a message to the aspx page. ...
0
by: Mrozik | last post by:
after parsing WSDL definition of java WebService, C# proxy class contains data strutures (I'm using RPC\encoded): public class DateString { /// <remarks/> public string value; }
3
by: Richards | last post by:
The .NET documentation has the following statement about "The IntPtr type can be used ...... as a common means of referring to data between languages that do and do not support pointers." Can...
3
by: Opa | last post by:
Hi , I have a form with javasript which launches a popup via the showModalDialog() method. I get the dialog to open, now I am trying to first get a reference to the calling form from the popup...
3
by: Vinz | last post by:
Hello everyone, With no C# nor C++ experience I wanted to make a C# WinForms client calling a C++ Win32 DLL. All day long I have been scraping knowledge from webpages and the C++ pocketreference...
13
by: Steve | last post by:
On page 392 of "Javascript the definitive guide" a function is called like this:- <form action="processform.cgi" onsubmit="return validateForm();"> Why, in this instance, is the return...
8
by: Yansky | last post by:
If I have the following function: function foo(){ alert('hi'); } and I don't need to pass any parameters to it, is calling it this way:
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.