cotonti.com : AJAX parts in plugs https://www.cotonti.com Последние сообщения в теме Cotonti en Thu, 09 Oct 2025 05:11:23 -0000 GHengeveld
See changeset 1220]]>
вс, 02 мая 2010 17:27:43 -0000
urlkiller

i got now the following problem when inserting html markup in my xml document it dont get parsed correctly.

seems like the .text() from juery is filtering out the whole markup like <h1> and such...

any ideas why it is breaking there?

Added 11 minutes later:

got it already was the cdata thing i was missing for the markup problem:
<![CDATA[".$msgrow['message']."]]>
$msgrow['message'] = sed_parse($msgrow['message']);
$msgrow['date'] = date('d.m.Y H:i:s',$msgrow['date']);
$msgrow['username'] = $msgrow['username'];
		
$sendToOut .= "\t<message>\n";
$sendToOut .= "\t\t<username>".$msgrow['username']."</username>\n";
$sendToOut .= "\t\t<userid>".$msgrow['userid']."</userid>\n";
$sendToOut .= "\t\t<date>".$msgrow['date']."</date>\n";
$sendToOut .= "\t\t<avatar>".$msgrow['avatar']."</avatar>\n";
$sendToOut .= "\t\t<messagebody><![CDATA[".$msgrow['message']."]]></messagebody>\n";
$sendToOut .= "\t</message>\n";

Added 16 minutes later:

hmm somehow it wont send the data when inserting new data over post.
i alwyays get a 930 back and get redirected ... ;( dont find the problem...

Added 3 minutes later:

ok to conclude this:

		$t->assign('MY_JS_FUNC', "$(document).ready(function(){
			timestamp = 0;
			updateMsg();
			$(\"form#myform\").submit(function(){
				$.post(\"plug.php?r=dashboard\",{
							message: $(\"#sendmessage\").val(),
							group_id: \"".$gid."\",
							user_id: \"".$usr['id']."\",
							x: \"".sed_sourcekey()."\",
							user_name: \"".$urow['user_name']."\",
							user_avatar: \"".$urow['user_avatar']."\",
							action: \"send\",
							time: timestamp
						}, function(xml) {
								addMessages(xml);
								$('#sendmessage').val('');
				});
				return false;
			});
		});");

											<form id="myform">
										 		<textarea class="minieditor" name="sendmessage" id="sendmessage"></textarea>
								 				<input type="submit" id="submiter" value="Absenden" style="margin-left:3px;padding:5px;font-size:12px;width:437px;">
								 			</form>

defined('SED_CODE') or die('Wrong URL');
// send header
sed_sendheaders();

$time 					= ($_SERVER['REQUEST_METHOD'] != 'GET') ? sed_import('time','P','INT') : sed_import('time','G','INT');
$action 				= ($_SERVER['REQUEST_METHOD'] != 'GET') ? sed_import('action','P','TXT') : sed_import('action','G','TXT');
$user_name 			= sed_import('user_name','P','TXT');
$user_avatar 		= sed_import('user_avatar','P','TXT');
$date_now 			= sed_import('time','P','TXT');
$user_id 				= sed_import('user_id','P','TXT');
$group_id 			= sed_import('group_id','P','TXT');
$message 			  = sed_import('message','P','TXT');

if($action == "send")
{
	$insert = sed_sql_query("INSERT INTO whiteBox_wave (`username`,`message`,`date`,`avatar`,`userid`,`groupid`) VALUES ('".$user_name."','".$message."','".$date_now."','".$user_avatar."','".$user_id."','".$group_id."')");
}

$msg = sed_sql_query("SELECT * FROM whiteBox_wave WHERE date>'".$time."' ORDER BY date ASC ");

if(sed_sql_numrows($msg) == 0) $status_code = 2;
else $status_code = 1;

$sendToOut .= "<?xml version=\"1.0\" ?>\n";
$sendToOut .= "<response>\n";
$sendToOut .= "\t<status>".$status_code."</status>\n";
$sendToOut .= "\t<time>".mktime()."</time>\n";
if($status_code == 1)
{
	while($msgrow = sed_sql_fetcharray($msg))
	{

		$msgrow['message'] 		= sed_parse($msgrow['message']);
		$msgrow['date'] 			= date('d.m.Y H:i:s',$msgrow['date']);
		$msgrow['username'] 	= sed_build_user($msgrow['userid'],$msgrow['username']);
		
		$sendToOut .= "\t<message>\n";
		$sendToOut .= "\t\t<username><![CDATA[".$msgrow['username']."]]></username>\n";
		$sendToOut .= "\t\t<userid>".$msgrow['userid']."</userid>\n";
		$sendToOut .= "\t\t<date>".$msgrow['date']."</date>\n";
		$sendToOut .= "\t\t<avatar>".$msgrow['avatar']."</avatar>\n";
		$sendToOut .= "\t\t<messagebody><![CDATA[".$msgrow['message']."]]></messagebody>\n";
		$sendToOut .= "\t</message>\n";
	}
}
$sendToOut .= "</response>";


header("Content-type: text/xml");
header("Cache-Control: no-cache");

echo $sendToOut;

ob_end_flush();


Added 45 minutes later:

its quite wierd. because i did yesterday something and today its not working anymore.
i guess i had smething working and deleted or changed it due to testing the parser thing so i think its only a minor problem with my code here..

but i think iam too blind today for seeing it..]]>
сб, 24 апр 2010 00:36:41 -0000
Trustmaster # urlkiller : @trustmaster

as i understand it the $("input[name=x]").val() is deprecated since 1.1.4 or so... it should be: $("input[@name=x]").val()
Vice versa.
http://api.jquery.com/category/selectors/]]>
пт, 23 апр 2010 14:20:09 -0000
urlkiller
iam using firebug as debugger woirking smooth.

my problem was the x i was sending it 2 times... ;( one in a hidden input (as default) and one as jquery var. i fixed that now...

@trustmaster

as i understand it the $("input[name=x]").val() is deprecated since 1.1.4 or so... it should be: $("input[@name=x]").val()

;)

{PHP.sys.xk} this is really helpful...

Added 7 minutes later:

btw i solved it more like the tut was:
but i did the changes to plug.php and the other file and i still get kicked onto the error page in the background (i see the updates after my POST request i get message.php?msg=950 ! BUT get not redirected and stay on the form part of my testsite). seems like some sort of wierd problem...
		$t->assign('MY_JS_FUNC', "$(document).ready(function(){
			timestamp = 0;
			updateMsg();
			$(\"form#myform\").submit(function(){
				$.post(\"plug.php?r=dashboard\",{
							message: $(\"#sendmessage\").val(),
							group_id: $(\"#group_id\").val(),
							user_id: $(\"#user_id\").val(),
							x: \"".sed_sourcekey()."\",
							user_name: $(\"#user_name\").val(),
							user_avatar: $(\"#user_avatar\").val(),
							action: \"send\",
							time: timestamp
						}, function(xml) {
								addMessages(xml);
								$('#sendmessage').val('');
				});
				return false;
			});
		});");

Added 41 seconds later:

above the highlighter bar seems broken when mixing code and the highlight tag ;)]]>
пт, 23 апр 2010 10:58:16 -0000
GHengeveld
I've fixed this in changeset 1213.
With these changes you can make POST request using the ajax hook.

Note that for POST, sending the sourcekey along with the request is required. You can easily put the key in your JS with the {PHP.sys.xk} tag (in tpl files), so you'd get something like this:

$.post('plug.php?r=abc&x={PHP.sys.xk}', 
{ "varname": "value" }, 
function(){ 
// do whatever 
});

Added 5 minutes later:

Also I really recommend testing your jQuery POST requests with RESTTest. It's easy to check the server's response to your POST request that way. (don't forget the sourcekey)]]>
пт, 23 апр 2010 05:18:22 -0000
Trustmaster
$("input[name=x]").val()
]]>
чт, 22 апр 2010 16:54:48 -0000
ez So the browser will wait for an answer (explaining the freeze up).

Maybe your xml anser never comes back? (so a timeout will occur)

What is x?
Is x also located as a field within your form or maybe in the cookies? If it is, then you do not have to send it.. maybe this gives a clash..

TIP:
You really shoud look at the jquery forms plugin..
That plugin is great and it works easy!

So a lot off questions and possibilities..]]>
чт, 22 апр 2010 02:50:46 -0000
urlkiller
i got the following Problem with the Ajax call here:
		$(document).ready(function(){
			timestamp = 0;
/*			updateMsg();
*/			$("form#myform").submit(function(){
				$.post("plug.php?r=dashboard",{
							message: $("#sendmessage").val(),
							name: $("#gid").val(),
							action: "postmsg",
							x: $("#x").val(),
							time: timestamp
						}, function(xml) {
								addMessages(xml);
								$('#sendmessage').val('');
				});
				return false;
			});
		});

when submiting the form i got a complete browser freeze. i circled the problem around the security parameter var X everytime i want to use this i got the complete crash.

anybody know where the problem is?]]>
ср, 21 апр 2010 23:36:50 -0000