我使用以下代码将信息添加到我的列表中,它工作正常。最重要的是,我想将下面的2变量(listDescription和payment)发送到网址,如下所示:
http://mywebsite.com/public/user/spent/?amount=的 listDescription &安培;帐户= 付款
我正在尝试使用ajax并使用以下代码发送信息,但它无法正常工作,无论如何都没有响应警报。请问我能得到一些帮助。谢谢。
$(document).ready( function() {
var listDescription;
var payment;
//prepending - working fine
$('#add_list').click( function() {
listDescription = $('#list_description').val();
payment = $('#payment').val();
$('.expense_list').prepend('<div>' + "\u00A3 " + listDescription + "\t\t\t" + payment + "\t" + '</div>');
//This is not working
$.ajax({
url: "htttp://mywebsite.com/public/user/spent/",
data: {
amount: listDescription,
account: payment
},
type: "GET",
async:true,
cache:false,
success: function (data) {
alert("success");
},
error: function (xhr, status, error) {
alert("error");
}
});
$('#list_form')[0].reset();
return false;
});
});
答案 0 :(得分:0)
可能会尝试在AJAX请求中添加数据类型JSON吗?
dataType:'json',
答案 1 :(得分:0)
$(document).ready( function() {
//prepending - working fine
var listDescription = $('#list_description').val();
var payment = $('#payment').val();
$('#add_list').click( function() {
$('.expense_list').prepend('<div>' + "\u00A3 " + listDescription + "\t\t\t" + payment + "\t" + '</div>');
//This is not working
$.ajax({
url: "htttp://mywebsite.com/public/user/spent/",
data: {
amount: listDescription,
account: payment
},
type: "GET",
async:true,
cache:false,
success: function (data) {
alert("success");
},
error: function (xhr, status, error) {
alert("error");
}
});
$('#list_form')[0].reset();
return false;
});
});
这应该有效:)