#StackBounty: #jquery #ajax #drupal #cors #drupal-8 Why is my Drupal 8 CORS setup not working?

Bounty: 200

Since Drupal 8.2 the cors setup is in core. In my services.yml (and default.services.yml) I have the following setup:

cors.config:
    enabled: true
    # Specify allowed headers, like 'x-allowed-header'.
    allowedHeaders: ['x-csrf-token','authorization','content-type','accept','origin','x-requested-with']
    # Specify allowed request methods, specify ['*'] to allow all possible ones.
    allowedMethods: ['*']
    # Configure requests allowed from specific origins.
    allowedOrigins: ['*']
    # Sets the Access-Control-Expose-Headers header.
    exposedHeaders: false
    # Sets the Access-Control-Max-Age header.
    maxAge: 1000
    # Sets the Access-Control-Allow-Credentials header.
    supportsCredentials: true

My domain a.com is htaccess password protected.

On domain b.com I try to load some API from domain a.com:

$.ajaxSetup({
  xhrField: {
    withCredentials : true
  },
  beforeSend: function (xhr) {
    xhr.setRequestHeader('Authorization', 'Basic Z2VuaXVzOmNvYXRpbmdz');
  }
});

request = $.ajax({
  url: apiBaseUrl + 'api/foobar',
  dataType: 'json',
  type: 'get',
  password: 'foo',
  username: 'bar'
});

In chrome it works fine, in firefox I get an error. The request headers:

Access-Control-Request-Method: GET
Access-Control-Request-Headers: authorization

Response is 401 “Authorization required”, it says request method is OPTIONS (?).

Whats wrong here?

Doing the same request in insomnia works perfectly fine.


Get this bounty!!!

#StackBounty: #javascript #jquery Ajax Tooltip – bypass so not to use bootstrap

Bounty: 50

I found this code on stackoverflow.com and I would like to ask how do I do the same but without using bootstrap, I would only like to use jquery (if needed) ?

The code below works great but I would like to know how would I do this without using bootstrap.

Thanks for any help.

CODE:

//code.jquery.com/jquery-compat-git.js
//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">



//
                html: true,
                placement: "auto",
                container: 'body',
                trigger: 'hover'
            });

            // show this LOADING popover
            el.popover('show');

            // requesting data from unsing url from data-poload attribute
            $.get(el.data('poload'), function (d) {
                // set new content to popover
                el.data('bs.popover').options.content = d;

                // reshow popover with new content
                el.popover('show');
            });
        },
        // Without this handler popover flashes on first mouseout
        function() { }
    );
});//]]> 




<img src="alerts.gif" data-poload="test3.php?id=1"><BR><BR><BR>
<img src="alerts.gif" data-poload="test3.php?id=2"><BR><BR><BR>
<img src="alerts.gif" data-poload="test3.php?id=3"><BR><BR><BR>


Get this bounty!!!

#StackBounty: #javascript #jquery #html #actionscript-3 #flash reload embedded swf in html page in IE

Bounty: 50

I have a swf file embedded in a html page. I want to reload the swf file without refreshing the page.

There is a same problem asked here: reload/ reset embedded swf on click

And I tried the accepted answer and it works in chrome:

var obj = $("object#flash_99674493");
obj.html(obj.html());

But it seems it doesn’t work in IE. How to make it work in IE?


Get this bounty!!!

#StackBounty: #javascript #jquery Running a jQuery function multiple times sequentially (for a Bookmarklet)

Bounty: 50

I’ve got the following jQuery code which I use in a Bookmarklet. It clicks on all the buttons on the page (with the class “Unfollow”) one by one, with a random time between each one…

javascript: (function() {
    var unfollowButtons = $('button.Unfollow');
    var index = unfollowButtons.length - 1;
    unfollow();

    function unfollow() {
        if (index >= 0) {
            $(unfollowButtons[index--])
                .click();
            setTimeout(unfollow, Math.floor((Math.random() * 1000) + 500));
        }
    }
})();

I’d like to run the above function again twice once it has completed its cycle.

Just running the function again causes that to run in parallel with the first function call.

How do I run the unfollow() function 2 or 3 times without them all running in parallel?


Get this bounty!!!

#StackBounty: #javascript #jquery #jqplot jqplot not show label end points

Bounty: 50

when I draw chart using jqplot, both end point of the chart does not show label, and I am not sure why. Please help
enter image description here

Here is my code (self-contained code, with all resources loaded)

<html>
<head>
</head>
<body>
    <input id="dashboardForm:j_idt49:4:hiddenChartData" type="text" name="dashboardForm:j_idt49:4:hiddenChartData" value="{&quot;data&quot;:[[843,1312,745,683,832,829,772,740,792,672,550,323]],&quot;dateFull&quot;:[[1,&quot;01/06&quot;],[2,&quot;02/06&quot;],[3,&quot;03/06&quot;],[4,&quot;04/06&quot;],[5,&quot;05/06&quot;],[6,&quot;06/06&quot;],[7,&quot;07/06&quot;],[8,&quot;08/06&quot;],[9,&quot;09/06&quot;],[10,&quot;10/06&quot;],[11,&quot;11/06&quot;],[12,&quot;12/06&quot;]],&quot;tick&quot;:[[1,&quot;01/06&quot;],[2,&quot;02/06&quot;],[3,&quot;03/06&quot;],[4,&quot;04/06&quot;],[5,&quot;05/06&quot;],[6,&quot;06/06&quot;],[7,&quot;07/06&quot;],[8,&quot;08/06&quot;],[9,&quot;09/06&quot;],[10,&quot;10/06&quot;],[11,&quot;11/06&quot;],[12,&quot;12/06&quot;]]}" class="soluongdonhangngay170" style="display:none;"> 
    <div style="height: 550px" class="soluongdonhangngay170170" />


http://app.fahasa.com:8084/ReportEngine/org.richfaces.resources/javax.faces.resource/org.richfaces/jquery.js 
http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jquery.jqplot.js?ln=js    
http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.dateAxisRenderer.js?ln=js   
http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.categoryAxisRenderer.js?ln=js   
http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.logAxisRenderer.js?ln=js    
http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.canvasTextRenderer.js?ln=js 
http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.canvasAxisTickRenderer.js?ln=js 
http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.canvasAxisLabelRenderer.js?ln=js    
http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.highlighter.js?ln=js    
http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.pointLabels.js?ln=js    
http://app.fahasa.com:8084/ReportEngine/faces/javax.faces.resource/jqplot/jqplot.enhancedLegendRenderer.js?ln=js 

jQuery(function(){
    var labels = ["Đơn Hàng Theo Ngày"];
  alert(jQuery(".soluongdonhangngay170").val());
  displayLineChartWithToggleLegend($(".soluongdonhangngay170").val(),$(".soluongdonhangngay170170"), labels, "Số Lượng Đơn Hàng Ngày");
});

function displayLineChartWithToggleLegend(data, target, label, chartTitle){
    if(data === "") return;
    var chartJsonData = $.parseJSON(data);
    var dataPlot = chartJsonData.data;
    var ticks = chartJsonData.tick;
    var showPointLabel = true;
    if(chartJsonData.data.length > 4){
        showPointLabel = false;
    }
    target.jqplot(dataPlot, {
        title: chartTitle,
        animate: true,
        axesDefaults: {
            labelRenderer: $.jqplot.CanvasAxisLabelRenderer
        },
        seriesDefaults: {
            showMarker: true
        },
        legend: {
            show: true,
            renderer: $.jqplot.EnhancedLegendRenderer,
            placement: "outsideGrid",
            labels: label,
            location: "ne",
            rowSpacing: "5px",
            rendererOptions: {
                // set to true to replot when toggling series on/off
                // set to an options object to pass in replot options.
                seriesToggle: 'normal',
                seriesToggleReplot: {resetAxes: true}
            }
        },
        axes: {
            xaxis: {
                label: 'Date',
                ticks: ticks,          
                tickInterval: 20,
                tickOptions: {
                    showGridline: false,
                    angle: -60,
                    fontFamily: 'Helvetica',
                    fontSize: '8pt'
                },                
            }
        },
        grid: {
            drawBorder: false,
            shadow: false,
            // background: 'rgba(0,0,0,0)'  works to make transparent.
            background: "white"
        },
        series: [
            {
                pointLabels: {
                    show: showPointLabel
                },
                rendererOptions: {
                    // speed up the animation a little bit.
                    // This is a number of milliseconds.
                    // Default for a line series is 2500.
                    animation: {
                        speed: 2000
                    },
                    smooth: true
                }
            }
        ]
    });

    target.bind('jqplotDataMouseOver', function(ev, seriesIndex, pointIndex, data) {
        var idx = seriesIndex;
        $('tr.jqplot-table-legend').removeClass('legend-row-highlighted');  
        $('tr.jqplot-table-legend').children('.jqplot-table-legend-label').removeClass('legend-text-highlighted');
        $('tr.jqplot-table-legend').eq(idx).addClass('legend-row-highlighted');
        var dateFull = chartJsonData.dateFull;
        $(this).find(".jqplot-title").html(dateFull[data[0] - 1][1] + " - " + data[1]);
        $('tr.jqplot-table-legend').eq(idx).children('.jqplot-table-legend-label').addClass('legend-text-highlighted'); 
    });

    target.bind('jqplotDataUnhighlight', function(ev, seriesIndex, pointIndex, data) {
        $('tr.jqplot-table-legend').removeClass('legend-row-highlighted');  
        $('tr.jqplot-table-legend').children('.jqplot-table-legend-label').removeClass('legend-text-highlighted');
        $(this).find(".jqplot-title").html(chartTitle);        
    });
}

</body>
</html>


Get this bounty!!!

#StackBounty: #javascript #jquery #jquery-ui #datepicker #jquery-ui-datepicker how to fake current date for jquery-ui-datepicker

Bounty: 50

I’m implementing a custom algorithm to disable dates depending on a set of rules that also depend on what the current day is.
To test that I would need to set the current date to a specific date.

I found this thread that just overwrites javascripts Date function.
My problem is that if I do that the calendar doesn’t work as expected anymore.
Most of the time all days are just missing, sometimes all are disabled.

var oldDate = Date;
Date = function (fake)
{
    if( ! fake ) return new oldDate('02/26/2017');

    return new oldDate(fake);
}
Date.prototype = oldDate.prototype;

How can I test the datepicker with a custom current date?
It should be as easy as setting up a jsfiddle (if possible):
https://jsfiddle.net/ge4bne97/


Get this bounty!!!

#StackBounty: #javascript #jquery #html #cordova #wcf How to display set access permission & display /hide div based on database va…

Bounty: 50

i want to set access permissions page where setting the permissions to the user to only view selected div’s only for ex:

There are 5 checkboxes in admin page and 5 div’s in user page if check 3 div user has to get 3 div only i am mapping userlocation & client location & username for setting access permissions and how to display / hide the div in user page based on the checkbox selection or database values?

There is user login separately and admin login separately . Her admin will disable certain features for certain users. using wcf rest and sql server as backend


Get this bounty!!!

#StackBounty: #javascript #jquery #html #css #google-maps Google Maps in jQuery Accordion works in jsFiddle, but maps do not load on my…

Bounty: 50

I am trying to simply make an expanding list of Google Maps which allow you to locate an item. Here I have a static HTML page where you can click records and they will expand to show you a Google Map. The map, however, only comes through as grey until you resize the page.

Here is the page with the problem (the extension says php, but it doesn’t actually have any): https://yt074.addons.la/tmp/track/list.php

I’m already calling google.maps.event.trigger(maps[i], 'resize'); within the code (as you can see by viewing source), and I have tried jQuery(window).trigger('resize');, window.dispatchEvent(new Event('resize')); and a few others to simulate a resizing of the window, but to no avail.

Here is a jsFiddle with the code from above literally copy/pasted into the fiddle and it works: https://jsfiddle.net/myingling/Lkdmp1zo/

Or here is a shorter version on my server which is not working: https://yt074.addons.la/tmp/track/fiddle.php

What am I missing on my server? Server is ubuntu running nginx on an AWS EC2 cluster, but once the code is client-side I don’t understand why that would matter (but better safe to explain).


Get this bounty!!!

#StackBounty: #javascript #c# #jquery #.net #winforms JQuery click() on anchor tag not firing from an injected script inside WebBrowser…

Bounty: 50

I am developing a web bot using WinForms WebBrowser control. Everything is working fine except for the second click() call in following code:

function SaveRecordClick() {
    try {
        var menuButton = $('#s_at_m_4');
        menuButton.click();             //<-- This is working
        var x = $('#s_at_m_4-menu li')[5];
        var saveLink = $(x).find('a')[0];
        if (saveLink != null){
            saveLink.click();           //<-- This is not working

            return "1";
        }
    }
    catch (err) {
        alert(err.message);
    }
    return "0";
}

saveLink is not null. I know this because I placed an alert() call inside the condition.

Updated code with suggested solutions

function SaveRecordClick() {
    try {
        var menuButton = $('#s_at_m_4');
        menuButton.click();
        var x = $('#s_at_m_4-menu li').eq(5);
        var saveLink = x.find('a').eq(0);
        if (saveLink != null) {
            alert(saveLink.html());
            saveLink.click();

            return "1";
        }
    }
    catch (err) {
        alert(err.message);
    }
    return "0";
}

But still the same problem. ‘alert()’ is working fine but html() is showing inner text instead of HTML of the anchor.

HTML Code

<li data-caption="Save Record                [Ctrl+S]" class="sbui-appletmenu-item  ui-menu-item" role="presentation">
<a href="javascript:void(0)" aria-disabled="false" class="ui-corner-all" id="ui-id-254" tabindex="-1" role="menuitem">Save Record                [Ctrl+S]</a>
</li>

ID of the anchor tag is dynamically generated.

Also, click() is triggering when the same code is executed from Google Chrome Console. So, could it be the issue with the WebBrowser control?


Get this bounty!!!

#StackBounty: #javascript #jquery #ajax #recaptcha How to verify recaptcha in server call?

Bounty: 50

SITUATION:

I used to check my recaptcha with a simple form submit with POST to “/login”.

I need to change my implementation for security reasons and would like to do something like:

1) Jquery form submit.

2) Make call to server to call verify recaptcha on the server.

3) Receive response without reloading page.

4) Accept login request or not based on response.


QUESTION:

It looks like I could make an AJAX request ? But I don’t know how.


CLIENT CODE:

Login

<button class="btn btn-default" id="loginButton">Submit</button> <span class="userLinks"> <a class="logLinks" href="/users/register">Register</a><a href="/users/password">Password?</a></span> </form> </div> </div> <% include ../partials/indexScripts %> <script> $("#loginForm").submit(function(e) { e.preventDefault(); var email = $("#loginEmail").val(); var password = $("#loginPassword").val(); // WOULD LIKE TO MAKE SERVER CALL HERE TO CHECK RECAPTCHA BUT I DONT KNOW HOW $this = $(this); $.ajax({ type: "POST", url: "users/register", data: $this.serialize() }).done(function(data) { if (successfulRecaptcha) { firebase.auth().signInWithEmailAndPassword(email, password ).then( authData => { } else { console.log("You are a robot!"); }

SERVER CODE:

router.post('/login', function(req, res, next) {
    verifyRecaptcha(req.body["g-recaptcha-response"], function(success) {
        if (success) {

        } else {

        }
    });
});


Get this bounty!!!