Log in

View Full Version : ajax post problem



xyeze
10-20-2011, 09:34 AM
hi everyone ; just i am very sorry for bad english :(

just demopage is that : http://xyeze.com/aqajax/levent/

my problem is ajax post problem..my code is that ...


this is index.php ;

/////////////



<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">

#ustkolon {
width:979px;
height:36px;
margin-left:4px;
margin-bottom:10px;
border: 1px dashed #3ca3c1;
background:#AEE1E2;
}
#solkolon{
float:left;
margin-left:4px;
overflow:auto;
background:#91CED2;
width:250px;
height: 500px;
border: 1px dashed #3ca3c1;
padding: 3px;
}

a.tryitbtn,a.tryitbtn:link,a.tryitbtn:visited,a.showbtn,a.showbtn:link,a.showbtn:visited
{
display:block;
font: normal 12px arial;color:#096F78;
background:#ffffff;
width:225px;
border: 1px dashed #ffffff;
padding:3px;
margin-bottom:4px;
text-decoration:none;
}

a.tryitbtn:hover,a.tryitbtn:active,a.showbtn:hover,a.showbtn:active
{
color:#ffffff;
text-decoration :none;
background-color:#0E929E;
}

#sagkolon{

overflow:auto;
margin-left:10px;
float:left;
background:#CBC3C1;
height:500px;
width:714px;
margin-right: 5px;
padding-bottom: 8px;
}
</style>
<script type="text/javascript">

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){

var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}


page_request.open('GET', url, true)
page_request.send(null)

}

function loadpage(page_request, containerid){

if (page_request.readyState == 1)
{
document.getElementById(containerid).innerHTML='<img src="../yenixyezeeee/tools/images/loading.gif" />';
}

if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
</script>


<div id="ustkolon">
<a class='uibutton confirm' title='yeni başlık açacağı' alt='yeni başlık açacağı' style='text-decoration:none;'
href="javascript:ajaxpage('cagrilanilk.php', 'sagkolon');">başlık aç</a>
</div>

<div id="solkolon"></div>

<div id="sagkolon">veri olmadımı burası gelir veri çağrıldımı bu kalkar sayfa gelir</div>


/////////////


this is cagrilanilk.php

/////////////



<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<div class="df" style="padding:10px;">

<form method="GET" action="javascript:ajaxpage('cagrilanilk2.php','sagkolon');">

<textarea id='fikrim' style='border-color:#BEF2DF;width:573px;height:150px;' class='content' name='fikrim'></textarea>
<input type="submit" class="uibutton confirm" value="sal başlığı ortama">

</form>

</div>


/////////////


end this is cagrilanilk2.php :((

////////////



<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?

$fikrim=$_GET['fikrim'];

echo "gelen veri ==>> $fikrim";

?>

////////////


please help me friends pleaseeeeee ... :(

$fikrim is not getting... :((


and demopage is that : http://xyeze.com/aqajax/levent/

jscheuer1
10-21-2011, 02:21 AM
I don't see any attempt at post, the form is using get. That's actually good because the ajaxpage function can't handle post, it can handle get.

BTW, the ajaxpage function appears to be stolen from this Dynamic Drive Script:

http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

You should restore the copyright notice.

OK, here's what I would try, on cagrilanilk.php change:


action="javascript:ajaxpage('cagrilanilk2.php','sagkolon');">

to:


action="javascript:ajaxpage('cagrilanilk2.php?fikrim=' + encodeURIComponent(document.getElementById('fikrim').value).replace(/(%20){1,}/g, '+'),'sagkolon');">

If that works out, great! Otherwise you'll need a different sort of AJAX script. In which case I'd suggest jQuery. But let's try this first and see what happens.

What I'd be most worried about is if there's a lot of text in the fikrim textarea, it might be too much for a get. In that case a post would be required.

Using jQuery and post -

index.php:


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">

#ustkolon {
width:979px;
height:36px;
margin-left:4px;
margin-bottom:10px;
border: 1px dashed #3ca3c1;
background:#AEE1E2;
}
#solkolon{
float:left;
margin-left:4px;
overflow:auto;
background:#91CED2;
width:250px;
height: 500px;
border: 1px dashed #3ca3c1;
padding: 3px;
}

a.tryitbtn,a.tryitbtn:link,a.tryitbtn:visited,a.showbtn,a.showbtn:link,a.showbtn:visited
{
display:block;
font: normal 12px arial;color:#096F78;
background:#ffffff;
width:225px;
border: 1px dashed #ffffff;
padding:3px;
margin-bottom:4px;
text-decoration:none;
}

a.tryitbtn:hover,a.tryitbtn:active,a.showbtn:hover,a.showbtn:active
{
color:#ffffff;
text-decoration :none;
background-color:#0E929E;
}

#sagkolon{

overflow:auto;
margin-left:10px;
float:left;
background:#CBC3C1;
height:500px;
width:714px;
margin-right: 5px;
padding-bottom: 8px;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function($){
var loading = '<img src="http://xyeze.com/yenixyezeeee/tools/images/loading.gif" alt="Loading . . ." title="Loading . . .">';
$('a.uibutton').click(function(e){
e.preventDefault();
$('#sagkolon').html(loading);
$.ajax({
url: 'cagrilanilk.php',
cache: false,
success: function(data){
$('#sagkolon').html(data);
}
});
});
$('#sagkolon form').live('submit', function(e){
e.preventDefault();
$.ajax({
url: 'cagrilanilk2.php',
cache: false,
beforeSend: function(){
$('#sagkolon').html(loading);
},
type: 'post',
data: $(this).serialize(),
success: function(data){
$('#sagkolon').html(data);
}
});
});
});
</script>
<div id="ustkolon">
<a href="#" class='uibutton confirm' title='yeni baslik açacagi' alt='yeni baslik açacagi' style='text-decoration:none;'>baslik aç</a>
</div>

<div id="solkolon"></div>

<div id="sagkolon">veri olmadimi burasi gelir veri çagrildimi bu kalkar sayfa gelir</div>

cagrilanilk.php:


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<div class="df" style="padding:10px;">

<form>

<textarea id='fikrim' style='border-color:#BEF2DF;width:573px;height:150px;' class='content' name='fikrim'></textarea>
<input type="submit" class="uibutton confirm" value="sal basligi ortama">

</form>

</div>

cagrilanilk2.php:


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php

$fikrim=$_REQUEST['fikrim'];

echo "gelen veri ==>> $fikrim";

?>