473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

AND(&) Symbol Messing Up Params

162 100+
I'm using the following AJAX code to send GET vars to my processing PHP file. This works great as is except that it will not accept a *&* (AND symbol) in the text input. It trys to pass what is after the *&* as a new GET var. I totaly get what is happening, just don't get how to fix it. I hope my example code is sufficient.

HTML:
Expand|Select|Wrap|Line Numbers
  1. <input type="text" class="inputbox" value="pb&j" id="input_name" name="input_name" onblur="javascript:makeRequest('my_file.php?new=',this.value);"/>
  2.  
javascript:
Expand|Select|Wrap|Line Numbers
  1. var http_request = false;
  2. function makeRequest(url, parameters) { //alert(parameters)
  3.     http_request = false;
  4.     if (window.XMLHttpRequest) { // Mozilla, Safari,...
  5.         http_request = new XMLHttpRequest();
  6.         if (http_request.overrideMimeType) {
  7.             // set type accordingly to anticipated content type
  8.             //http_request.overrideMimeType('text/xml');
  9.             http_request.overrideMimeType('text/html');
  10.         }
  11.     } else if (window.ActiveXObject) { // IE
  12.         try {
  13.             http_request = new ActiveXObject("Msxml2.XMLHTTP");
  14.         } catch (e) {
  15.             try {
  16.                 http_request = new ActiveXObject("Microsoft.XMLHTTP");
  17.             } catch (e) {}
  18.         }
  19.     }
  20.     if (!http_request) {
  21.         alert('Cannot create XMLHTTP instance');
  22.         return false;
  23.     }
  24.     http_request.onreadystatechange = alertContents;
  25.  
  26.     // FOR POST VARS
  27.     //http_request.open('POST', url, true);
  28.     //http_request.send(parameters);
  29.  
  30.     // FOR GET VARS
  31.     http_request.open('GET', url + parameters + "&time=" + get_date(), true);
  32.     http_request.send(null);
  33. }
  34.  
  35. function alertContents() {
  36. if (http_request.readyState == 4) {
  37.  if (http_request.status == 200) {
  38.     //alert(http_request.responseText);
  39.     result = http_request.responseText;
  40.     document.getElementById('myspan').innerHTML = result;
  41.  } else {
  42.     alert('There was a problem with the request.');
  43.  }
  44. }
  45. }
  46.  
Jun 20 '07 #1
2 1717
empiresolutions
162 100+
My solutions was to add the replace() function at line 2 of the following code.

Expand|Select|Wrap|Line Numbers
  1. function makeRequest(url, parameters) {
  2.         parameters = parameters.replace(/&/g,"%26");
  3.     http_request = false;
  4.  
  5.         ... rest of function
  6. }
  7.  
Jun 20 '07 #2
acoder
16,027 Expert Mod 8TB
You could use encodeURIComponent. See link.
Jun 20 '07 #3

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

Similar topics

6
by: mali_djuro | last post by:
Hi all, i used JDOM to create XML file. first, i get data from database and create Document object. in some data i have quotas, so it makes replacment in content of elements. for example: if i...
0
by: Thomas Scheffler | last post by:
Hi, I runned in trouble using XALAN for XSL-Transformation. The following snipplet show what I mean: <a href="http://blah.com/?test=test&amp;test2=test2">Test1&amp;</a> <a...
2
by: Francesco Moi | last post by:
Hello. I designed a form to edit some DataBase's fields. But some of these fields contain '&lt;' and '&gt;' characters. And these characters are '<' and '>' in HTML. So if want to edit these...
1
by: Franck | last post by:
Hi, is it possible to catch called WebMethods name and params in the Application_BeginRequest ? Thks for help
11
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved...
11
by: BenI | last post by:
Hello, I have a XML file using Iso 8859-1 encoding. Every time when I try to put & character as Tag's value like <tag>This is & character</tag> Exception is shown in my application. I use...
33
by: onkar | last post by:
#include<stdio.h> int main(int argc,char **argv){ int a={1,2,3,4,5}; printf("%p\n%p\n",a,&a); return 0; } gives me : 0xbfe837a0
0
by: Sells, Fred | last post by:
I had some code originally that printed the sql and params when I called the .execute method. I removed it but it still prints. I rebooted and renamed files and still it prints. I am totally...
0
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I have a series of business objects and grid views. I there a way to set tthe parameter for a grid view using a params array. So far ai can't seem to be able to do it. I keep getting...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.