No dobra chyba chciałem za szybko wszystko opisać. Cały kod:
ng-controllers.js:
Kopiuj
angular.module('Textarea', [])
.controller('TextAreaCtrl', function(){
this.isButtonVisible = function(){
return this.text;
}
this.send = function(){
var data = {data: this.text}; // poprzednio jak wyżej
$.post("/data.php",
data,
function() {
alert("data saved");
});
}
});
index:
Kopiuj
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl" ng-app='Textarea'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Angular - Textarea</title>
<link rel='stylesheet' type='text/css' href='style.css' />
<script type='text/javascript' src='jquery.min.js'></script>
<script type='text/javascript' src='angular.min.js'></script>
<script type='text/javascript' src='ng-controllers.js'></script>
</head>
<body style='padding:0px; margin:0px;' onload=''>
<div class='Cont' ng-controller='TextAreaCtrl as ctrl'>
<div class='TextAreaCont'>
<textarea ng-model='ctrl.text' placeholder='Write something...'></textarea>
</div>
<div class='ButtonCont' ng-show='ctrl.isButtonVisible()'>
<button ng-click='ctrl.send()'>Send</button>
</div>
</div>
</body>
</html>
php który ma wykonać kod z parametrem przez POST
Kopiuj
<?php
echo $_POST["data"];
?>
Nie wiem czy dobrze zrozumiałem. Ostatecznie chciałbym, aby data.php tworzył plik z przekazaną wartością, ale do tego wolę dojść sam. Na razie chce wiedzieć co źle robię. Programowałem już w php, ale było to dawno temu