Jump to content

sending sepcial characters through ajax


funbinod

Recommended Posts

edit ---- (sorry for spelling mistake on topic. its "special" in stead of "sepcial")

 

 

I've created ajax request to get some data. I works fine for normal data but if it contains special character like "&", then it does nothing.

 

following is the ajax request----

function getSid(){var XMLHttpRequestObject = false;if (window.XMLHttpRequest) {	XMLHttpRequestObject = new XMLHttpRequest();} else if (window.ActiveXObject) {	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHttp");}XMLHttpRequestObject.onreadystatechange = function(){	if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {		document.getElementById('sid').value = XMLHttpRequestObject.responseText;	}}var item = document.getElementById('item').value;XMLHttpRequestObject.open('POST', 'ajax/sid.php');XMLHttpRequestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");XMLHttpRequestObject.send("item=" + item);}

and this is the page that I derive data from---

<?php##################### sid.php #####################require_once('../functions.php');header("content-type: text/xml");$item = ($_POST['item']); // this works fine if I put $item = 'this & that' but if I send the same value from ajax, it doesn't work.if ($stmt =  $mysqli->prepare("SELECT sid FROM stock WHERE item=? AND cid=?")) {	$stmt->bind_param('si', $item, $cid);	$stmt->execute();	$stmt->bind_result($sid);	$stmt->fetch();	echo $sid;} else {	echo 'error: '.$mysqli->error;}?>

please help resolving this problem-----

Edited by funbinod
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...