Saturday, 1 April 2017

Difference between the tag and get request

I have a perhaps simple question. What would be the difference between an <a> tag and a normal GET request with any element. I know the <a> tag automatically sends you to the url specified in its href attribute. So I assume that a Get request does something similar in it's success callback (as demonstrated below)

But let's say that I also want to send some information along with a normal get request when a for example <span> element is clicked on so I write:

   $('span').click(() => {
    $.ajax({
        url: '/someurl',
        type: 'GET',
        data: {
            title: someTitle,
            email: someEmail
        },
        success: (data) => {
                window.location = '/someurl';

        }
    });
});

Is there any way to achieve this with an <a> tag (the sending information to the so it's available in req.query.title and req.query.email ? Doing this will run my app.get('/someurl',(req,res)=>{})twice because I am sending a GET request to send the data (title and email) and then I am making another GET request when I write window.location = '/someurl' How can I redo this so that it only sends the GET request ONCE but also allows for the sending and storing information to the req object.



via JohnNoob

No comments:

Post a Comment