0

I need to send the page title and process the data. But when I perform without the x variable it works fine. But when I pass pass the x variable it will stop working.

window.onload = function() {
    if(document.readyState === 'complete') {
        
        
 var x = document.getElementsByTagName("title")[0];

                        $.post({
                              type: "POST",
                              method: 'POST',
                              cache: false,
                              processData: false,
                              dataType : "text",
                              url: "http://localhost:8000/search?title=kishore",
                              data: {title: x},
                                             success: function(data) {
                                             console.log(data);


  });

};
}
  • `title: x` should be `title: x.textContent` – wOxxOm Dec 20 '20 at 18:43
  • Thanks For that @wOxxOm ! But no luck. It's not sending the data to the server! https://ibb.co/cFhprPs –  Dec 20 '20 at 18:49
  • 1
    Are you sure about the `post()` syntax. As per jQuery the syntax should be `$post(url, data, callback)` when using `$.post()` do you still need to specify type: "POST" and method: "POST", the dataType also seems to be incorrect as you are passing json data. Lastly why do you want to send the same piece of info both as query string param & as post data – Donkarnash Dec 20 '20 at 20:00
  • @Donkarnash we don't use type and method but to be sure it works, rather it's no use if we specify too. But the dataType should be specified because I am writing this script in content.js script where the website tells illegal invocation. I just want to the string param so that: http://localhost:8000/search?title='' It could replace kishore here –  Dec 21 '20 at 06:29
  • Modern Chrome disallows cross-origin requests in content scripts, see [How to stop CORB from blocking requests to data resources that respond with CORS headers?](https://stackoverflow.com/q/55214828) – wOxxOm Dec 21 '20 at 07:30
  • @wOxxOm I have used CORS in laravel. used as a middleware for routes it allows so when I searched for illegal invocation I did this https://stackoverflow.com/questions/10324594/jquery-illegal-invocation –  Dec 21 '20 at 07:56
  • 1
    If the current site doesn't allow cross-origin requests then it doesn't matter how you configured your server. You'll have to make the request in the background script as explained in the topic I've linked. – wOxxOm Dec 21 '20 at 08:24

0 Answers0