gpt4 book ai didi

forms - 如何在 ember.js 中使用 ajax 发送 Post 请求?

转载 作者:行者123 更新时间:2023-12-04 11:06:09 25 4
gpt4 key购买 nike

我想使用 ember.js 向服务器发送 POST(而不是 GET)请求。我不知道我需要哪个功能在 “这里是哪个函数” ,但我想将其发送到服务器以进行登录请求。

App.LoginController = Ember.ObjectController.extend({
actions: {
userLogin: function(user) {
// which function here?
?? ("http://siteurl/api/authentication/login/&username=" + user.username + "&password=" + user.password + "");
this.transitionTo('cat');

},

cancelLogin: function() {
this.transitionTo('menu');
}
}
});

App.UserFormComponent = Ember.Component.extend({
actions: {
submit: function() {
this.sendAction('submit', {
username: this.get('username'),
password: this.get('password')
});
},

cancel: function() {
this.sendAction('cancel');
}
}
});

在这里模板代码
  <script type="text/x-handlebars" data-template-name="login">
<header class="bar bar-nav">
<h1 class="title">inloggen</h1>
{{#link-to 'menu' class="icon icon icon-bars pull-right"}}{{/link-to}}
</header>
<!-- SHOW LOADER -->
<div class="content">
<div class="content-padded">
{{user-form submit="userLogin" cancel="cancelLogin" submitTitle="login"}}
</div>
</script>

<script type="text/x-handlebars" data-template-name="components/user-form">
<form {{action "submit" on="submit"}}>
<p><label>gebruikersnaam {{input type="text" value=username}}</label></p>
<p><label>wachtwoord {{input type="password" value=password}}</label></p>
<input type="submit" class="btn btn-primary btn-block" {{bindAttr value=submitTitle}}>
<button class="btn btn-negative btn-block" {{action "cancel"}}>Cancel</button>
</form>
</script>

最佳答案

Ember 没有任何内置的通信层,您可以使用 jquery 进行此类调用。

App.LoginController = Ember.ObjectController.extend({
actions: {
userLogin: function(user) {
$.ajax({
type: "POST",
url: "http://siteurl/api/authentication/login/&username=" + user.username + "&password=" + user.password,
data: { name: "John", location: "Boston" }
})
this.transitionTo('cat');

},

cancelLogin: function() {
this.transitionTo('menu');
}
}
});

关于forms - 如何在 ember.js 中使用 ajax 发送 Post 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24327092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com