Jump to content

AND(&) Symbol Messing Up Params


cesarcesar

Recommended Posts

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:

<input type="text" class="inputbox" value="pb&j" id="input_name" name="input_name" onblur="javascript:makeRequest('my_file.php?new=',this.value);"/>

 

Javascript:

var http_request = false;
function makeRequest(url, parameters) { //alert(parameters)
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
	http_request = new XMLHttpRequest();
	if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	}
} else if (window.ActiveXObject) { // IE
	try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	}
}
if (!http_request) {
	alert('Cannot create XMLHTTP instance');
	return false;
}
http_request.onreadystatechange = alertContents;

// FOR POST VARS
//http_request.open('POST', url, true);
//http_request.send(parameters);

// FOR GET VARS
http_request.open('GET', url + parameters + "&time=" + get_date(), true);
http_request.send(null);
}

function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
    //alert(http_request.responseText);
    result = http_request.responseText;
    document.getElementById('myspan').innerHTML = result;
} else {
    alert('There was a problem with the request.');
}
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.