我正在使用Django (1.4.2)在Pinax框架内开发一个Stripe with应用程序,并使用:
除了ajax响应(以JSON格式)之外,我已经完成了所有工作,似乎没有任何ajax回调处理,因此在浏览器中显示为原始JSON数据:
{"html": "\n\n<div class=\"change-card\">\n <h2>Current Card</h2>\n <p class=\"lead\">\n \n Current card on file is a <strong>Visa</strong>\n ending in the digits <strong>4242</strong>.\n \n </p>\n \n \n \n <form action=\"/payments/a/change/card/\" data-stripe-key=\"\" class=\"form ajax\" data-replace-closest=\".change-card\" method=\"POST\">\n <div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='<>' /></div>\n <input name=\"stripe_token\" type=\"hidden\" />\n <a href=\"\" class=\"btn btn-primary change-card\">Change Card</a>\n </form>\n</div>\n"}这个问题似乎是相似的,但没有官方的回答,提交者似乎已经弄清楚了(根据评论),但这些建议对我不起作用。
详细信息:
我正在使用Chrome和Firefox中的python manage.py runserver进行测试。
我刚刚开始使用stripe应用程序,在我为自己的具体需求量身定做之前,我刚刚使用了django-stripe支付的例子。
我正在运行的测试用例涉及使用django-stripe支付的标准ajax表单来更改存储的信用卡:
<form action="{% url 'payments_ajax_change_card' %}" data-stripe-key="{{ STRIPE_PUBLIC_KEY }}" class="form ajax" data-replace-closest=".change-card" method="POST">
{% csrf_token %}
<input name="stripe_token" type="hidden" />
<a href="" class="btn btn-primary change-card">{% if request.user.customer.card_kind %}Change{% else %}Add{% endif %} Card</a>
</form>在我的基本模板中有一些javascript被调用,并显示表单从条形进入卡的细节-当选择“更改卡”按钮。我不认为这是错的-我直接从这里那里拿来的。
我有以下这一职能:
<script src="{% static "js/jquery-1.9.1.min.js" %}"></script>
<script src="//checkout.stripe.com/v2/checkout.js"></script>下面这个
<script src="{% static "js/eldarion-ajax.min.js" %}"></script>在令牌返回之后(以及随后的表单提交事件),将执行以下视图代码:
@require_POST
@login_required
def change_card(request):
try:
customer = request.user.customer
send_invoice = customer.card_fingerprint == ""
customer.update_card(
request.POST.get("stripe_token")
)
if send_invoice:
customer.send_invoice()
customer.retry_unpaid_invoices()
data = {}
except stripe.CardError, e:
data = {"error": e.message}
return _ajax_response(request, "payments/_change_card_form.html", **data)再一次..。这是开箱即用的django-条纹支付代码。接下来发生的事情是上面提到的原始JSON。
发布于 2014-05-22 12:49:06
好吧,我解决了。事实证明,这确实是一个jQuery问题。我在我的应用程序中引用两个jQuery文件。当我删除第二个问题,并坚持上面的问题中提到的一个,它是有效的!我的信用卡细节更新,如预期在页面(虽然缓慢)。
因为我使用的是pinax框架,所以它会自动附带jquery引用。least.This中的Django调试工具栏需要包含在"base.html“文件中:
{% block script_base %}{% endblock %}("base.html“位于这里:base.html
幸运的是,base.html提供了一个名为"jquery_src“的过填块,因此在我的应用程序中的"site_base.html”文件中,我只在底部输入了以下内容:
{% block jquery_src %}{% endblock %}这删除了第二个jQuery库。
我还尝试使用jQuery v1.11.0,它被认为是这是我前面提到的问题中的错误,而且它也起作用了。
https://stackoverflow.com/questions/23494604
复制相似问题