Jump to content

Process Php Code Without Refreshing Hole Site.


davidb52

Recommended Posts

Hello,first of all sorry for my bad english but I already tried: Helpmij.nl, pfz.nl and yahoo answers and I can't find the right answer. And is always a hard choise put it in php or javascript.So I want to make something that process php code without refreshing site (because if you down at my site and delete a message or something like that you go to the top of the page).I don't want that anymore because it's not that user friendly.If you still don't know where I am talking about, you can compare it with Facebook.If you comment a status update you don't go to the top of the page you stay where you where (don't think that's English xD).Or if you delete a message you don't go to the top of the page, I want something like that.I know ajax but I am a javascript noobie (only html/css/php). So this is what I tried:http://net.tutsplus....h-using-jquery/and than step 4, but the problem is: url: "bin/process.php" I can't do something like that because I have sessions on profile.php that not exist in process.php. you can use ajax for this. Or you can just create a hidden iframe, and set the form target as the name of the iframe. this way, when the form is submitted, the form output will be loaded into the iframe, check my post for more info, i use jQuery. <form method="post" target="iframe_1" action="process.php">...</form> <iframe style="display:none" src="process.php" name="iframe_1" id="iframe_1">...</iframe> Same problem I need some session variable's from profile.php, and if I put that in process.php it will give an error. so this is the code:profile.php (it's all on the same page (profile.php) that's why it's working now, but the problem it refresh the hole page so if you click on it if you on the bottom of the site it goes to the top of the site and you have to scroll back)biggest problem these sessions:

$id=$_SESSION['id'];// id other (if you check some one else profile$ido = $row['id'];

add message into database:

// handle postppmif ($_SERVER['REQUEST_METHOD']=='POST' and isset($_POST['message']) and $_GET['m']=="ok") {   if(strlen($_POST['message'])>=5){   $errorstrlen2 = $_POST['message'];	 if(strlen($errorstrlen2)>2000){	 $count = strlen($errorstrlen2);	 echo 'Too long message <b>' . $count . '</b>, allowed (2000)';	 }	 else{  $time = date("y-m-d H:i:s", time());  $time = convert_datetime($time);	 $message = $_POST['message'];	 $query = "		  INSERT INTO usersppm		  (		  usersid		  , ido		  , message	, time		  )		  VALUES		  (		  '" . mysql_real_escape_string( $ido ) . "'		  ,'" . mysql_real_escape_string( $id ) . "'		  ,'" . mysql_real_escape_string( $message ) . "'	,'" . mysql_real_escape_string( $time ) . "'		  )";		  $queryupload = mysql_query($query);	header("location: profile.php?n=$name");		  die("You auto redirect to <a href='profile.php?n=$name'>profile</a>.");	}	}else{$errorstrlen = $_POST['message'];echo "You need more than 5 charachters.";}}

form:

<form action='?m=ok&n=<?php echo $name; ?>' method='POST'><span style="color:rgb(20,70,250);">Personal profile message:</span> <br /><TEXTAREA name="message" COLS=45 ROWS=5 maxlength="2000"><?php if(isset($errorstrlen)){ echo $errorstrlen; } ?></TEXTAREA><input type='hidden' name='n' value='<?php echo $easynamep; ?>'><input type='submit' value='ppm' class="button"></form>

I was thinking about scrollto(0,0) or something like that, something that save's every 3 second the position and if you refresh the site it goes back to that place, is that an option? please can anyone help me?

Link to comment
Share on other sites

Since AJAX won't load session variables, you'll have to use a hidden iframe. It's obvious you'll need Javascript. In order to make it work wothout Javascript, have a default action for the form and then add the target attribute with Javascript. I'm not sure where you have a problem. Can you point to any one specific problem that's happening?

Link to comment
Share on other sites

I don't have any problems using sessions with ajax requests. PHP sessions are not per page, they are per session (hence the name). If you're using sessions correctly then the data is accessible on all pages on your domain.

Link to comment
Share on other sites

ofcource forget to put sessions above process.php thnx!BUT....It works, the site doesn't go to the top of the page after submit thnx!but I want to refresh the div if it's posted.I found some tut on the internet but example:<div id="test">blabla</div> and i use some method this will happen: <div id="test">hole site refresh in hereeverything else and<div id="test">blabla (refresh)</div></div> so how could i refresh only 1 div?I will search for the script i used. but if you now how to solve this already thx!

Link to comment
Share on other sites

Either set up the script to always update the same element, where you write the responseText to that element, or if the element you want to update changes then you'll need some way for PHP to send the element ID to tell Javascript which element to update. You may want to set up Javascript to get the ID of the element it's going to update, send that to PHP along with the request, and PHP can send back the same ID.

Link to comment
Share on other sites

Could you guys help me one other time, please?1. How can I just refresh only an div (can't find any script)2. I got profile.php with that iframe, only problem let's say i want to refresh 1 div (if i have the code) if i put it in process.php:<?phpIf(everything is good){?><script>Reload div</script><?php}?> but it's not working because this is process.php and not profile.php so how could i say in process.php that i want to refresh an div in profile.php

Link to comment
Share on other sites

Ajax is only used for updating the database, or changing the info on the current page. If the information on profile.php comes from a database, then you can always send an ajax request to change that database information. The next time they load the profile page it will have the updated information from the database.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...