Jump to content


Php Code Needs Ajax To Prevent Page Reload

php ajax code jquery serial

  • Please log in to reply
No replies to this topic

#1 strydom

  • Members
  • PipPip
  • Member
  • 10 posts

Posted 18 November 2012 - 08:24 PM

Hi there,
Basically what i need is for my site to not refresh every time i click one of the buttons. I have got as far as finding out that it requires AJAX but i don’t have a clue how to use it :confused:

This is some of my code...it basically covers the main parts but if you need more then please ask...
$(function() {
	 var tabs = $( "#tabs" ).tabs({collapsible: true, active:"flase"});
	 tabs.find( ".ui-tabs-nav" ).sortable({axis:"x", stop:function() {tabs.tabs( "refresh" );}

$(function() {
	 $( ".box" ).draggable({containment: "#restrictor", scroll: false, snap: true, opacity: 0.35,
cancel: ".box-content"

	 $( ".box" ).addClass( "ui-widget ui-widget-content ui-corner-all" )
		 .find( ".box-header" )
		 .addClass( "ui-widget-header ui-corner-all" )
		 .prepend( "<span class='ui-icon ui-icon-minusthick'></span>")
		 .find( ".box-content" );

	 $( ".box-header .ui-icon" ).click(function() {
		 $( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
		 $( this ).parents( ".box:first" ).find( ".box-content" ).toggle();

$( "#container" ).disableSelection();

$(function() {
	 $( "input[type=submit], #Buttons, button" )
		 .click(function( event ) {

}, 1000);

<!------------------------Serial Port/Commands/Functions--------------------------->

if (isset($_GET['action'])) {


$serial = new phpSerial();


exec('mode COM3 BAUD=96 PARITY=n DATA=8 STOP=1 xon=off octs=off rts=on');


if ($_GET['action'] == "on") {
$file = fopen("Home_Automation/Includes/lights.txt","w");
fwrite($file, "1");

} else if ($_GET['action'] == "off") {
$file = fopen("Home_Automation/Includes/lights.txt","w");
fwrite($file, "0");

} else if ($_GET['action'] == "unlock") {
$file = fopen("Home_Automation/Includes/doors.txt","w");
fwrite($file, "1");



<!--------------------------------Main Container----------------------------------->
<div id="restrictor" class="ui-widget-content">

<!--------------------------------Controll Switches-------------------------------->
<div class="box">
<div class="box-header">Doors</div>
<div class="box-content">
<a class="button" href="<?php echo $_SERVER['PHP_SELF'] . '?action=unlock' ?>">Unlock</a>
<div id="PHP">
$file = fopen("Home_Automation/Includes/doors.txt", "r") or exit("Unable to open file!");
	 if (fgetc($file)==1)
			 echo "<img src=\"Home_Automation/Images/Door_Open.gif\" />";

			 echo "<img src=\"Home_Automation/Images/Door_Closed.gif\" />";
<a class="button" href="<?php echo $_SERVER['PHP_SELF'] . '?action=lock' ?>">Lock</a>

It’s not really in order as i cut bits out but that covers the basic code...

If someone could please show me some code snippets that i would need to include or something that would be great :happy-04:


Edited by strydom, 18 November 2012 - 08:25 PM.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users