[英]X-Editable - How to pull form data using ajax
I am using x-editable and would like to know how to populate my select element using jquery and ajax. 我正在使用x-editable,并且想知道如何使用jquery和ajax填充我的select元素。
[EDIT - For clarity] [编辑-为了清楚]
This is my code: 这是我的代码:
jQuery(document).ready(function() {
//toggle `popup` / `inline` mode
$.fn.editable.defaults.mode = 'popup';
var getSource = function() {
var url = "/api/rpc/payments/status_options";
$.ajax({
type: 'GET',
async: true,
url: url,
dataType: "json",
success: function(responseObject){
}
});
};
//make status editable
$('.payments-click').editable({
type: 'select',
title: 'Select status',
placement: 'right',
value: 2,
source: getSource()
/*
//uncomment these lines to send data on server
,pk: 1
,url: '/post'
*/
});
});
I am trying to get the source: 我正在尝试获取来源:
source: getSource()
From the function but am not 100% sure how to return the data from the Ajax call. 从函数,但不是100%确定如何从Ajax调用返回数据。
I resolved this with the help of this post: How do I return the response from an asynchronous call? 我在这篇文章的帮助下解决了这个问题: 如何从异步调用返回响应?
Here is my solution: 这是我的解决方案:
jQuery(document).ready(function() {
//toggle `popup` / `inline` mode
$.fn.editable.defaults.mode = 'popup';
function getSource() {
var url = "/api/rpc/payments/status_options";
return $.ajax({
type: 'GET',
async: true,
url: url,
dataType: "json"
});
}
getSource().done(function(result) {
$('.payments-click').editable({
type: 'select',
title: 'Select status',
placement: 'right',
value: 2,
source: result
/*
//uncomment these lines to send data on server
,pk: 1
,url: '/post'
*/
});
}).fail(function() {
alert("Error with payment status function!")
});
});
Try this 尝试这个
<a href="javascript:void(0)" id="status" data-type="select" data-title="Select Status"></a>
<script>
$.getJSON("api/rpc/payments/status_options", function (list) {
$('#status).editable({
prepend: "",
pk: 1,
source: list,
name: "status"
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.