【问题标题】:AJAX send method and button visibilityAJAX 发送方法和按钮可见性
【发布时间】:2015-01-20 23:46:22
【问题描述】:

所以,有一个文本区域,在面板上的那个发送按钮下,在输入第一个字符后显示,isButtonVisible() 方法控制它。它通过 AJAX send() 方法将 textarea 中的文本发送到 data.php,其中来自 textarea 的数据必须保存在 .txt 文档中。 .js 文件名为 ng-controllers.js 谁能帮我解决这个问题?我没有使用 angular.js 的经验

这是我的 HTML 文件的样子:

<!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"><style type="text/css">@charset "UTF-8";[ng\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide{display:none !important;}ng\:form{display:block;}.ng-animate-block-transitions{transition:0s all!important;-webkit-transition:0s all!important;}.ng-hide-add-active,.ng-hide-remove{display:block!important;}</style>

<title>Angular - Textarea</title>

<link rel="stylesheet" type="text/css" href="./Angular - Textarea_files/style.css">

<script type="text/javascript" src="./Angular - Textarea_files/jquery.min.js"></script><style type="text/css"></style>

<script type="text/javascript" src="./Angular - Textarea_files/angular.min.js"></script>

<script type="text/javascript" src="./Angular - Textarea_files/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="text" placeholder="Write something..." style="margin: 0px; height: 106px; width: 795px;"></textarea>
    </div>
    <div class="ButtonCont" ng-show="ctrl.isButtonVisible()">
        <button ng-click="ctrl.send()">Send</button>
    </div>
</div>


</body></html>

【问题讨论】:

  • 我不知道如何用角度制作它
  • 所以您希望有人用 Angular 编写 ajax 帖子,然后为您编写将其保存在 .txt 文件中的服务器端位?
  • 没有。只是 ajax 以角度发布,也许应该如何看待 data.php 来接收它和这个按钮可见的东西。我需要帮助,因为我不知道该怎么做。我真的很绝望。

标签: javascript jquery html ajax angularjs


【解决方案1】:

angualr 中的 Ajax 调用使用 $http 提供程序 full documentation here

这和你在 jquery 中做 $.ajax 的方式非常接近,即

var httpPost = $http({
    method: "post",
    url: "example.com/posts",
    data: {
        // some data here
    }
});

然后你分配一个函数在成功时运行

httpPost.success(
    function( html ) {
        // do something here 
    }
); 

【讨论】:

  • 谢谢。也许你会知道按钮可见?
猜你喜欢
  • 2012-06-15
  • 2023-03-16
  • 1970-01-01
  • 2011-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-17
  • 2011-09-02
相关资源
最近更新 更多