1

my ajax post doesnt go through. Any idea on how to fix this? it doesnt show anything in the console log. /ajax_check works fine but /report doesnt. I really really need help on this... ive tried console logs to debug but they do not appear.. please help thank you

IN JAVASCRIPT (named popup.js)

    chrome.contextMenus.create({
        title: "Report a Scam Image",
        contexts:["image"],
        onclick: function(info) {
            handleURL(info.srcUrl);
        }
    });

    function handleURL(url) {

            alert(url);
            $.ajax({
                    url: "http://localhost:8023/report",
                    type: "GET",

                    data: {
                        link: url,
                    }

            }).done(function(data) {

            })
            .fail(function() {

                    alert("Error");



            });
    }


    In NodeJS (server.js)

    app.post('/report', function(req, res){
        var getUrl = req.body.link;
        console.log(getUrl);
        var sql = "INSERT INTO reports (link) VALUES ("+getUrl+")";
        console.log(sql);
          con.query(sql, function (err, result) {
            if (err) throw err;
            console.log("1 report entered.");
                res.end("success");
          });



    });
1
  • 1
    try type: "POST" in ajax request Commented Apr 22, 2019 at 2:53

1 Answer 1

1

Try this one. Add type as post and datatype as json

           $.ajax({
                    url: "http://localhost:8023/report",
                    type: "POST",
                    dataType: 'json',
                    data: {
                        link: url,
                    }

            }).done(function(data) {

            })
            .fail(function() {
                    alert("Error");
            });       

Sign up to request clarification or add additional context in comments.

2 Comments

it still doesnt work. i have another app.post called "/send_data" in my nodejs that works, only this one "/report" doesnt work even though i use the exact same code.
what error you are getting? and what you are sending to backend. its only data or data with imagedata?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.