Jump to content

Problem with AJAX POST


x1nick

Recommended Posts

Im trying to make a textarea with a button which saves the document (via php) now I can get the script to post the textarea's content's so I can process it with PHP but it dosen't seem to post it EXACTLY as displayed

 

Here is the javascript

function ajaxpost (url,poststr,divid) {
xmlhttp = GetXmlHttpObject();
if (xmlhttp == null) {
  		alert ("Browser does not support HTTP Request");
	return;
  	}	
xmlhttp.onreadystatechange = function() {
    	if(xmlhttp.readyState == 4) {
      		handleresponse(xmlhttp.responseText,divid);
    	}
  	}
xmlhttp.open('POST', url, true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", poststr.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(poststr);

}

function handleresponse(response,divid) {
document.getElementById(divid).innerHTML = response;
}

function GetXmlHttpObject() {
if (window.XMLHttpRequest)   {
  		// code for IE7+, Firefox, Chrome, Opera, Safari
  		return new XMLHttpRequest();
  	}
if (window.ActiveXObject) {
  		// code for IE6, IE5
  		return new ActiveXObject("Microsoft.XMLHTTP");
  	}
return null;
}

 

The code thats run onclick of the button

savebutton.onclick = function () { 
  		var code = "tplcode=" + escape(self.mirror.getCode()); 
	ajaxpost('index.php?acms&s=ajax&amod=tpl&ajax=save&tplid=<?=$_REQUEST['tplid']?>',code,'messagearea');                
  	};

 

Now this appears to work ok besides one problem + symbols.

 

sbox.style.top = (realoffset(searchfield,"offsetTop")+searchfield.offsetHeight-1)+"px";

 

Which comes out like this

sbox.style.top = (realoffset(searchfield,"offsetTop") searchfield.offsetHeight-1) "px";

 

As you can see its missed out the + from the code thats been submitted within the text area.

Is the problem caused by var code = "tplcode=" + escape(self.mirror.getCode());  and how do I resolve this?

Link to comment
Share on other sites

  • 3 weeks later...
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.