Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-22-2011, 11:59 AM   PM User | #1
capypara
New Coder

 
Join Date: Aug 2011
Posts: 49
Thanks: 1
Thanked 0 Times in 0 Posts
capypara is an unknown quantity at this point
Passing jquery values to php

Hi, i have a question regarding passing jquery values to php. I tried using Firebug, and my values got displayed in Firebug's post parameter/source sections, but the value was not even in my post array when i var_dump the array. Is there something wrong with my code?

Code:
//JS code
function check_pwd()
{
	pwd = prompt("please input your password","");
	$.post("/someurl", { jspwd: pwd } );
	return true;
}
PHP Code:
//PHP code, using CodeIgniter syntax. jspwd was not included in the post values array
var_dump($this->input->post()); 
I tried to set a hidden value in my html using

Code:
pwd = prompt("please input your password","");
$("#pwd").attr('value', pwd);
as well but it did not work too. If anyone has other suggestions on how to pass values from a Javascript popupbox to a php page I am willing to try it too.
capypara is offline   Reply With Quote
Old 11-22-2011, 12:06 PM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
Quote:
Originally Posted by capypara View Post
function check_pwd()
{
pwd = prompt("please input your password","");
$.post("/someurl", { jspwd: pwd } );
return true;
}
That is not a native JavaScript code. Do you use a JavaScript framework/library? Which one? JQuery? Prototype? MooTools? Google API? Yahoo API? Other?

Don't make us guess, please.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 11-22-2011, 12:16 PM   PM User | #3
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 530 Times in 524 Posts
devnull69 will become famous soon enough
If (by any chance) you are using jQuery ... did you try to access the parameter using the PHP standard $_POST["jspwd"]?
devnull69 is offline   Reply With Quote
Old 11-22-2011, 12:17 PM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,584
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
You guys should read the thread title or the first sentence in the OP’s post where it says which framework this is. It was just posted in the wrong forum.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 11-22-2011, 12:27 PM   PM User | #5
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
Quote:
Originally Posted by VIPStephan View Post
You guys should read the thread title or the first sentence in the OP’s post where it says which framework this is. It was just posted in the wrong forum.
Well yes... Could be... except that I have never heard about "jquery values"
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 11-24-2011, 12:43 AM   PM User | #6
capypara
New Coder

 
Join Date: Aug 2011
Posts: 49
Thanks: 1
Thanked 0 Times in 0 Posts
capypara is an unknown quantity at this point
Quote:
Originally Posted by devnull69 View Post
If (by any chance) you are using jQuery ... did you try to access the parameter using the PHP standard $_POST["jspwd"]?
Hi there, yes i have tried it and i get the same error.

A PHP Error was encountered
Severity: Notice
Message: Undefined index: jspwd

And sorry if i did not describe the problem well enough. I am using PHP for server side and JQuery and Javascript for client side, and using the Codeigniter framework for this project.

The main thing that i want is to pass values from a popup input box from client side to my PHP side, but both $.post and setting a value by using $("#pwd").attr('value', pwd); does not seem to be working.
Am i using this function $.post correctly?

Last edited by capypara; 11-24-2011 at 03:06 AM..
capypara is offline   Reply With Quote
Old 11-24-2011, 06:04 AM   PM User | #7
capypara
New Coder

 
Join Date: Aug 2011
Posts: 49
Thanks: 1
Thanked 0 Times in 0 Posts
capypara is an unknown quantity at this point
Regarding the main problem where i need to pass a value from a popup input box from client side to my PHP side,

$("#pwd").attr('value', pwd);

This method works now after some problem solving. However I still cant get $.post to work =/ Maybe i still dont understand how $.post functions...............
capypara is offline   Reply With Quote
Old 11-24-2011, 09:14 AM   PM User | #8
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 530 Times in 524 Posts
devnull69 will become famous soon enough
One way of working with $.post is like this
Code:
$.post(url, {parameters}, callback);
url is a string containing the (relative or absolute) URL to the server side script (PHP in your case)

parameters is a list of parameters. Example for you jspwd parameter
Code:
{'jspwd' : $('#pwd').val()}
The PHP script will then receive the parameter as $_POST["jspwd"]

callback is a function that will be executed after the request has successfully finished.
Code:
$.post('path/to/your.php', {'jspwd': $('#pwd').val()}, function(data) {
   alert(data);  // this will alert the output of the PHP script
});
Most importantly: $.post() starts an asynchronous request which means that the "Javascript program flow" will continue to execute even if the request is not yet finished. So if you have a construct like this
Code:
function whatever() {
   $.post(...);
   return true;
}
then the "return true" will be executed before(!) the request finishes.
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
capypara (11-24-2011)
Old 11-24-2011, 10:07 AM   PM User | #9
capypara
New Coder

 
Join Date: Aug 2011
Posts: 49
Thanks: 1
Thanked 0 Times in 0 Posts
capypara is an unknown quantity at this point
Thanks for the explanation devnull69 =) I have seen several sites that include the third parameter but i had no idea what that was used for. Will take a good look at $.post again later on.
capypara is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:51 AM.


Advertisement
Log in to turn off these ads.