我需要了解從JS到Python的簡單Ajax調用。我有一個Python函數。該函數使用一個簡單的參數並返回結果。我想從js發送這個參數,並得到js的函數結果。我嘗試如下.python函數是可以的,但js方面我知道我犯了一些錯誤。這裏是我的python代碼,function.py:Django中使用Ajax與JS和Python之間的數據集成
from suds.client import Client as Client
def get_result_by_code(promocode):
url="http://service.emobile.az:8080/ws-loyalty-
program/cp/loyaltyprogram.wsdl"
client = Client(url)
result = client.service.loyaltyProgramCalculate(
amount=1000,
authKey='TEST6aede35740f2b9d2248b0ab6b878',
identicalCode=promocode,
terminalCode=2166)
if str(result[2])=="SUCCESS":
status = 1
else:
status = 0
return status
此函數返回1或0與promocode。
而我的javascript功能如下。我知道這個功能是錯誤的,需要修復:
function get_result_by_code() {
promocode = $('#bakcelPromo').val();
$.ajax({
type: "GET",
url: "\docflow\projects\modules_2",
dataType: "json",
async: true,
data: {"promocode": promocode},
succes: function (json) {
$('#output').html(json.message);
}
}); }在JS
與上次計算的功能,將在屏幕上播放的是:
function calculate() {
if (get_result_by_code.val() == 1)
calculated_premium = calculated_premium * 0.2
else calculated_premium = calculated_premium
calculated_premium = Math.ceil(calculated_premium)