• 1400/02/25

ارسال دو request در fetch :

سلام خسته نباشید.

وقتی از fetch استفاده میکنم به جای یک request دوتا میفرسته مشکلش کجاست؟

api هم تست کردم مشکلی نداشت.

استفاده در main.js :

 

noteApi.AddNote(noteData)
                    .then(function(data) {
                        helpers.showMessage('successfully updated to local db!');
                        setTimeout(function() {
                            window.location.href = '/';
                        }, 1000);
                    });

 

api.js :

const NOTE_API_ADDRESS = "https://localhost/api/notes/";


var noteApi = (function() {

    function GetAllNotes() {
        return fetch(NOTE_API_ADDRESS);
    }

    function GetNote(id) {
        return fetch(NOTE_API_ADDRESS + id);
    }

    function AddNote(data) {
        return fetch(NOTE_API_ADDRESS, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Accept': 'application/json'
            },
            body: JSON.stringify(data)
        });
    }

    function UpdateNote(data) {
        return fetch(NOTE_API_ADDRESS + data.NoteId, {
            method: 'PUT',
            headers: {
                'Content-Type': 'application/json',
                'Accept': 'application/json'
            },
            body: JSON.stringify(data)
        })
    }


    function DeleteNote(id) {
        return fetch(NOTE_API_ADDRESS + id, {
            method: 'DELETE',
        });
    }


    return {
        GetAllNotes: GetAllNotes,
        GetNote: GetNote,
        AddNote: AddNote,
        UpdateNote: UpdateNote,
        DeleteNote: DeleteNote
    };
})();
  • 1400/02/25
  • ساعت 13:50

سلام 

عجیبه تا حالا این مشکل رو نداشتم 

دیباگ کنید مشکل پیدا میشه 


logo-samandehi