Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am simply making an ajax call to store input data, but it returns html code of the file instead of the expected data.The files are latest.php & latest.js. This question has been asked several times but none of the solutions seem to be working for me. Could anybody please help me out?

What I have tried:

JavaScript
$(document).ready(function () {

    $('#myForm').on('submit', function () {

        var question = $('input[name=quest]').val();
        var answer = $('input[name=ans]').val();

        $.ajax({
            type: 'POST',
            url: 'latest.php',
            dataType: 'text',
            data: {
                quest: question,
                ans: answer
            },

            success: function (result) {

                console.log(result);
                $('#message').html('Data saved successfully.');

            },

            error: function (e) {

                alert('Error: ' + e);

            }

        });

        return false;

    });

});
Posted
Updated 13-Oct-20 1:07am
v2
Comments
F-ES Sitecore 12-Oct-20 12:07pm    
Are you serving the files from a webbrowser (does the address bar look like http://someserver/yourpage) and not just loading them into the browser as files from disk (the url will be like file://c:\somefolder\yourpage)?
ZurdoDev 13-Oct-20 10:00am    
It depends on what latest.php returns. It must be returning all the html so you need to change that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900