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
https://forums.phpfreaks.com/topic/169471-problem-with-ajax-post/
Share on other sites

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.