我有一個$ .ajax()函數正常工作並返回一個結果,我想我做了一切需要的數據綁定進展順利。
頁上基本上加載從$。阿賈克斯()追加到表中的數據,但問題是,數據不附加像它應該。我錯過了什麼嗎?
HTML:
<div class="row">
<div class="col-md-12 overflow-table">
<table class="table" id="table">
<thead class="head-color thead-inverse">
<tr>
<th style="border-top-left-radius: 10px; border-left:1px solid transparent;">NAME</th>
<th>CLIENT-ID</th>
<th>URL</th>
<th style="border-top-right-radius: 10px; border-right:1px solid transparent;">ACTIONS</th>
</tr>
</thead>
<tbody id='table-redirect'>
<tr class='lightgrey'>
<td contenteditable="true">{{ agr.name }}</td>
<td>{{ agr.client_id }}</td>
<td contenteditable="true">{{ agr.url }}</td>
<td>
<img src="http://mobisteinlp.com/redirect/public/img/edit.svg"><a href='http://mobisteinlp.com/redirect/public/click.php/?id=%3C?php%20echo%20$id;?%3E'><img src="http://mobisteinlp.com/redirect/public/img/copy.svg"></a>
</td>
</tr>
<tr class='lightgrey'>
<td contenteditable="true">{{ agr.name }}</td>
<td>{{ agr.client_id }}</td>
<td contenteditable="true">{{ agr.url }}</td>
<td>
<img src="http://mobisteinlp.com/redirect/public/img/edit.svg"><a href='http://mobisteinlp.com/redirect/public/click.php/?id=%3C?php%20echo%20$id;?%3E'><img src="http://mobisteinlp.com/redirect/public/img/copy.svg"></a>
</td>
</tr>
<tr class='lightgrey'>
<td contenteditable="true">{{ agr.name }}</td>
<td>{{ agr.client_id }}</td>
<td contenteditable="true">{{ agr.url }}</td>
<td>
<img src="http://mobisteinlp.com/redirect/public/img/edit.svg"><a href='http://mobisteinlp.com/redirect/public/click.php/?id=%3C?php%20echo%20$id;?%3E'><img src="http://mobisteinlp.com/redirect/public/img/copy.svg"></a>
</td>
</tr>
<tr class='lightgrey'>
<td contenteditable="true">{{ agr.name }}</td>
<td>{{ agr.client_id }}</td>
<td contenteditable="true">{{ agr.url }}</td>
<td>
<img src="http://mobisteinlp.com/redirect/public/img/edit.svg"><a href='http://mobisteinlp.com/redirect/public/click.php/?id=%3C?php%20echo%20$id;?%3E'><img src="http://mobisteinlp.com/redirect/public/img/copy.svg"></a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
JAVASCRIPT:
//VARIABLES
var url = "http://mobisteinlp.com/redirect/redirect";
agr = 0;
//VUE.JS REDIRECT VIEW MODEL
var redirect = new Vue({
el: '#redirect',
data: {
agr1: []
},
mounted() {
this.getAll(); //DISPLAY TABLE ON PAGE LOAD
},
methods: {
//
getAll: function() {
var self = this;
console.log('teste');
$.ajax({
url: url + "/getAll",
type: "POST",
dataType: "json",
success: function(response) {
console.log(response); //
self.agr1 = response;
console.log(self.agr1);
console.log('success!');
},
error: function() {
console.log('error');
} //end error function
}); //end $.ajax() request
}, //end getAll function
} //end methods
}) //end vue.js instance
'但問題是數據沒有像它應該添加的那樣作爲問題描述是不夠的。請提供期望的結果和您得到的結果。 – GillesC
該表在頁面加載時顯示爲空,當您(重新)加載時應該填充它。 – Timmy
你能告訴你得到了什麼樣的回答,它是一個數組,對象還是對象數組? –