| | |
How to send & as data using _POST method using Ajax
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 2
Reputation:
Solved Threads: 0
Hi All,
I am trying to send some data using Ajax and recieve that data in php code using _POST method.
But my data contains "&" and _POST method takes it as a seperating token and data after tht does not get passed. Does anyone has a solution to this.
Code snippet:
And on server side when I use
it takes & as a seperator which is present as data.
Please someone let me know the workaround or approach to this.
I am trying to send some data using Ajax and recieve that data in php code using _POST method.
But my data contains "&" and _POST method takes it as a seperating token and data after tht does not get passed. Does anyone has a solution to this.
Code snippet:
PHP Syntax (Toggle Plain Text)
params = "q="+str+"&p="+str1; //here str1 contains data which has & xmlHttp.open("POST",url,false); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.send(params);
And on server side when I use
$posted = &$_POST ; it takes & as a seperator which is present as data.
Please someone let me know the workaround or approach to this.
Last edited by peter_budo; Mar 24th, 2008 at 7:20 am. Reason: Keep It Organized - please use [code] tags
•
•
Join Date: Mar 2008
Posts: 2
Reputation:
Solved Threads: 0
Thanks John for the input. This what I have done. If one wants to encode and decode the URL in javascript then above reference is fine. In my case i needed to encode at javascript and and decode inside php. The function to be used inside php code is
$p is the string which has encoded value. And the first 2 parameters just does enough to decode back whatever [CODE ] encodeURIComponent [/CODE] has done.
Thanks
preg_replace('/%([0-9a-f]{2})/ie', 'chr(hexdec($1))', (string) $p); $p is the string which has encoded value. And the first 2 parameters just does enough to decode back whatever [CODE ] encodeURIComponent [/CODE] has done.
Thanks
Last edited by rajivloharuka; Mar 25th, 2008 at 2:38 am.
•
•
Join Date: Nov 2007
Posts: 86
Reputation:
Solved Threads: 6
just out of curiosity, would str_replace not have worked easier for this?
You have a string (as a variable at least) and you know what other string is inside of it (or could be inside of it), and you know what you want to replace it with.
http://us.php.net/manual/en/function.str-replace.php
Sage
You have a string (as a variable at least) and you know what other string is inside of it (or could be inside of it), and you know what you want to replace it with.
http://us.php.net/manual/en/function.str-replace.php
Sage
![]() |
Other Threads in the PHP Forum
- Previous Thread: How to arrange a Profile.
- Next Thread: send e-mail every new entry on table on db
Views: 2239 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download duplicates dynamic echo email error execution file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link links login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote replace script search select server session sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





