How to get a cross-origin resource sharing (CORS) post request working

I finally stumbled upon this link “A CORS POST request works from plain javascript, but why not with jQuery?” that notes that jQuery 1.5.1 adds the Access-Control-Request-Headers: x-requested-with header to all CORS requests. jQuery 1.5.2 does not do this. Also, according to the same question, setting a server response header of Access-Control-Allow-Headers: * does not … Read more

How to retrieve checkboxes values in jQuery

Here’s one that works (see the example): function updateTextArea() { var allVals = []; $(‘#c_b :checked’).each(function() { allVals.push($(this).val()); }); $(‘#t’).val(allVals); } $(function() { $(‘#c_b input’).click(updateTextArea); updateTextArea(); }); Update Some number of months later another question was asked in regards to how to keep the above working if the ID changes. Well, the solution boils down … Read more

How can I use jQuery in Greasemonkey?

Perhaps you don’t have a recent enough version of Greasemonkey. It was version 0.8 that added @require. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js If you don’t have 0.8, then use the technique Joan Piedra describes for manually adding a script element to the page. Between version 0.8 and 0.9, @require is only processed when the script is first … Read more

jQuery: how to get which button was clicked upon form submission?

I asked this same question: How can I get the button that caused the submit from the form submit event? I ended up coming up with this solution and it worked pretty well: $(document).ready(function() { $(“form”).submit(function() { var val = $(“input[type=submit][clicked=true]”).val(); // DO WORK }); $(“form input[type=submit]”).click(function() { $(“input[type=submit]”, $(this).parents(“form”)).removeAttr(“clicked”); $(this).attr(“clicked”, “true”); }); }); In … Read more

Can you have multiple $(document).ready(function(){ … }); sections?

You can have multiple ones, but it’s not always the neatest thing to do. Try not to overuse them, as it will seriously affect readability. Other than that , it’s perfectly legal. See the below: Multiple $(document).ready() Try this out: $(document).ready(function() { alert(‘Hello Tom!’); }); $(document).ready(function() { alert(‘Hello Jeff!’); }); $(document).ready(function() { alert(‘Hello Dexter!’); }); … Read more

Find text string using jQuery?

jQuery has the contains method. Here’s a snippet for you: <script type=”text/javascript”> $(function() { var foundin = $(‘*:contains(“I am a simple string”)’); }); </script> The selector above selects any element that contains the target string. The foundin will be a jQuery object that contains any matched element. See the API information at: https://api.jquery.com/contains-selector/ One thing … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)