をaplication。コントローラで
var dataToSend = { fundraiser_id: <%= @fundraiser.id %>,
amount: $("#amount").val(),
currency: $('#donor_donation_currency').val(),
comment: $('#donor_donation_comment').val(),
anonymous: $("#donor_donation_anonymous").is(":checked"),
donor_email: $('#email').val(),
donor_name: $('#name').val(),
donor_city: $('#city').val(),
donor_country: $('#country').val() };
$.ajax({
type: "POST",
dataType:'JSON',
async: true,
data:dataToSend,
success: function(json){
$('#id_amount').val(json.amount);
$('#custom_content').val(json.custom);
},
error:function (xhr, ajaxOptions, thrownError){
console.dir(xhr);
console.dir(thrownError);
}
});
Iは
def get_paypal_button
@fundraiser = Fundraiser.where(:id => params[:fundraiser_id]).last
if params[:currency] == 'INR'
amount_in_sgd = params[:amount].to_f/@fundraiser.sgd_to_inr.to_f
elsif params[:currency] == 'USD'
amount_in_sgd = params[:amount].to_f*@fundraiser.usd_to_sgd.to_f
else
amount_in_sgd = params[:amount].to_f
end
puts '----------finding donor-------------'
@donor = Donor.find_or_initialize_by_email(params[:donor_email])
@donor.update_attributes(:name => params[:donor_name], :city => params[:donor_city], :country => params[:donor_country])
custom = @donor.id.to_s + "::" + params[:anonymous].to_s + "::" + params[:comment].to_s
@hash = {:amount => amount_in_sgd, :custom => custom}.to_json
respond_with(@hash) do |format|
format.json { render :json => @hash }
end
端
Iは、デバッガを使用して、(正しい)が得られる@hashの値
"{\"amount\":15.0,\"custom\":\"2::false::\"}"
を得るようにデータを処理してい
しかし、エラーの場合に書いたコードをajaxリクエストが実行していて、空のレスポンスが得られています。
私は数日前に同様のコードが動作していたため、すべてを試してみました。あなたが期待するようおそらく
私はあなたのハッシュで '.to_json'を使うのを見ています - あなたはこれを呼び出す必要はありません。 – MikDiet
私もまだ空の応答:( – rtcoms
を得ることは、それがデータ型に小文字のJSONを使用するのに役立つだろうと – DGM