檢查Magnific Popup plugin documentation,您可以找到AJAX type的特定部分。根據它,您可以通過使用ajax
和settings
屬性添加AJAX選項:
ajax: {
settings: null, // Ajax settings object that will extend default one - http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings
// For example:
// settings: {cache:false, async:false}
您可以使用該選項使用POST
方法,而不是GET
方法(默認)發送AJAX,這種方式不公開URL中的字段。
現在,您可以將它們設置爲data-
屬性,而不是在地址中添加參數,而是使用.data()
將其動態添加到呼叫中。
的HTML:
<cfoutput>
<a class="editRecord" href="editRecord.cfm" data-recordid="RecID" data-field1="val1">
<img src="../images/edit_icon.png" />
</a>
</cfoutput>
和JavaScript初始化:
$('.editRecord').magnificPopup({
type: 'ajax',
preloader: false,
ajax: {
settings: {
method: "POST",
data: {
recordID: $(this).data("recordid"),
field1: $(this).data("field1"),
// similar with the rest of the fields
}
}
}
});
我測試的代碼在本地...和無疾而終。這就像this
在magnificPopup()
函數中不可用。我繞到這個問題通過使用each()
功能像這樣先選擇字段,然後應用彈出Magnific酒店插件:
$(".editRecord").each(function() {
$(this).magnificPopup({
type: 'ajax',
preloader: false,
ajax: {
settings: {
method: "POST",
data: {
recordID: $(this).data("recordid"),
field1: $(this).data("field1"),
// similar with the rest of the fields
}
}
}
});
});
也許不是最好的解決辦法,但它在我跑的測試工作。
可能會幫助你https://api.jquery.com/data/ –