0

I've a problem with an ajax call in Knockout.js

    exports.prepareCashbackReceipt = function () {
        exports.receiptUrl(null);
        exports.isLoadingReceipt(true);

        $.post('/api/user/PrepareReceipt', JSON.stringify({ receiptNr: exports.data().NextReceiptNr(), amount: exports.cashbackPts() }))
            .done(function (retunedData) {
                console.log(retunedData);
                exports.isLoadingReceipt(false);
                exports.receiptUrl(retunedData.AWSObjectKey);
            })
            .fail(function (ex) {
                toastr['error']('Unable to create receipt, please try again later');
                console.log(JSON.stringify(ex));
                exports.isLoading(false);
                exports.isLoadingReceipt(false);
            })
    }

the PrepareReceipt method creates a pdf file (the receipt) and returns a string with the id of the receipt.

Now, the pdf is correctly created, and also the id is returned. But, for some reason the call fails.

enter image description here

I also tried to return a json string, and it fails again... is there a property, for example near responseText, to look into, that helps me to understand what is going wrong?

Update

the preceiding object that i logged in console is this https://drive.google.com/file/d/16a7GhCB1xHfHnkRKYCuGsrPgp_-psN4A/view?usp=sharing

here is the full chrome log https://drive.google.com/file/d/1yzPeIp1APhhytSUk7pzV-A5LZ-T4LLcn/view?usp=sharing

but I think it's not so interesting to determine what wrong is happening excepting for this string

[18604:10208:0801/151001.007:INFO:CONSOLE(152)] "[object Object]", source: https://localhost:44378/Scripts/ViewModels/portfolio.js (152)

but the chrome debugger console drew my attention to this:

enter image description here

so, in this moment, I'm turning my attention to the view.

Thanks in advance

Francesco
  • 2,042
  • 2
  • 19
  • 29
  • `statusText: "parseerror"` ? Is that something normal ? – Noah Boegli Jul 31 '20 at 16:48
  • Yes but that error is not so explicit – Francesco Jul 31 '20 at 17:12
  • By "it fails", is the `.fail()` callback getting executed? If so, is the exception getting logged? That would be helpful to see – devNull Jul 31 '20 at 17:20
  • Yes, the .fail(ex) callback is executed and I also have a console.log(ex) instruction, and the ex is an object – Francesco Jul 31 '20 at 17:27
  • Could you paste the contents of the `ex` that gets logged? That might help in determining what's causing the failure – devNull Jul 31 '20 at 17:37
  • Ok, tomorrow I'll try this https://stackoverflow.com/questions/7627113/save-the-console-log-in-chrome-to-a-file – Francesco Jul 31 '20 at 17:59
  • @devNull the call fail because jQuery.parseJSON can't parse a string that isn't a valid JSON (in this case a a linearized pdf). The strange part is that I don't return directly a pdf but a key to download it in a second moment. In any case, now I've more details to correct the bug. – Francesco Aug 01 '20 at 15:24
  • 3
    it looks rather like the actual pdf-file being returned than a key – john Smith Aug 03 '20 at 22:50
  • This is a server side issue, you're returning something incorrectly. – Nimesco Aug 10 '20 at 11:45

0 Answers0