【发布时间】:2019-08-14 07:27:11
【问题描述】:
这就是我尝试通过 json 向我的 javascript 发送内容的方式。来自 Stripe 向 3d (SCA) 付款
问题出在来自 strip API 的值上,它告诉我它是“值不能为空。参数名称:输入”,当我只运行它时它就会出现用js(ajax)
[HttpPost]
[Produces("application/json")]
[Route("Members/AddMembership/{id}/{CompaniesId}")]
public async Task<IActionResult> AddMembership(MembersView model)
{
try
{
//more here....
model.PiinVoice = subscription.LatestInvoice.PaymentIntent.ClientSecret;
//more here....
return Json(model.PiinVoice);
}
catch(Exception e)
{
TempData[TempDataClass.Error] = true;
TempData[TempDataClass.ErrorMsg] = HelperText.ExceptionError + e.Message;
//return RedirectToAction("", "User");
return Json(e.Message);
}
}
Javascript:
$.ajax({
url: '/Members/AddMembership/' + Id + '/' + CompaniesId, //jump to httppost action,meet [Route("Members/AddMembership/{id}/{CompaniesId}")]
dataType: "json",
data: "",
type: "Post",
contentType: 'application/json',
success: function (result) {//receive response from httppost action
//result is the response of the httppost action,you can handle it
console.log("New: " + Id, CompaniesId);
console.log(result.PiinVoice)
//var paymentIntentSecret = document.getElementById('PiinVoice').value;
//stripe.handleCardPayment(paymentIntentSecret).then(function (result) {
// if (result.error) {
// // Display error.message in your UI.
// // Inform the user if there was an error.
// var errorElement = document.getElementById('card-errors');
// errorElement.textContent = result.error.message;
// } else {
// // The payment has succeeded. Display a success message.
// stripeTokenHandler(result.token);
// }
//});
},
error: function (xhr) {
console.log(xhr)
}
});
如果我查看 result.PiinVoice 那么它给了我 undefined 但如果我只写结果然后它给我“值不能为空。参数名称: 输入"
所以我想对我的问题做的是:我怎样才能完成,以便我通过 json 发送的结果进入 js,然后我可以使用它来剥离。
由于现在的问题是我的控制器中的值绝不会出现在我的 js ajax 中
【问题讨论】:
-
尝试调试代码,看看是否在 pinvoice 中获取数据
-
我已经尝试调试:imgur.com/EZP34K4 就像我看不到哪里出了问题。或许你能明白为什么我不能调试js和控制器了。
标签: javascript c# json