jQWidgets Forums

jQuery UI Widgets Forums Grid Get json from s https url (ssl)

This topic contains 7 replies, has 2 voices, and was last updated by  AndySimpson 11 years ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • Get json from s https url (ssl) #48439

    AndySimpson
    Participant

    Hi guys,

    I have a problem. My grid gets data from a secure source – httpS (!).
    Now, for testing purpose, I added the exact same data to a local file called data.php.

     <script type="text/javascript">
                $(document).ready(function() {
                    var url = "data.php";
                    
                    // prepare the data
                    var source =
                            {
                                datatype: "json",
                                datafields: [
                                    {name: 'id'},
                                    {name: 'name'},
                                    {name: 'type'},
                                    {name: 'seats'},
                                    {name: 'building'},
                                    {name: 'devices'}
                                   // {name: 'comment'}
                                ],
                                id: 'id',
                                url: url,
                                pager: function (pagenum, pagesize, oldpagenum) {
                        // callback called when a page or page size is changed.
                                 },
                                root: 'data',
                                sortcolumn: 'name',
                                sortdirection: 'asc'
                            };

    This works just perfect. Data was copy pasted from the https-source.

    Now, if I enter the https-source:

    
    <script type="text/javascript">
                $(document).ready(function() {
                    var url = "https://app.psycho.unibas.ch/raumbuchung/overview/json/";
                   ...

    it won’t work – “No data to display”. I know that the url will only open inside the Intranet. I access it from the inside, so no problem there.
    Is there a special way to tell JQWidgets to access https data? My google research came back with no useful results.
    Thanks you in advance!

    cheers
    Andy

    Get json from s https url (ssl) #48441

    Peter Stoev
    Keymaster

    Hi Andy,

    Have you tried using “jsonp” instead? I think that it should be used instead of “json” for url with “https”.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Get json from s https url (ssl) #48589

    AndySimpson
    Participant

    Hi Peter
    thanks for your answer. Indeed I tried jsonp, but it still won’t work, unfortunately. I just post my code here, maybe the error is obvious for an expert 🙂

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <title id='Description'>In this example the Grid is bound to a Remote Data.</title>
            <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
            <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> 
            <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
            <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script> 
            <script type="text/javascript" src="../../jqwidgets/jqxgrid.columnsresize.js"></script> 
            <script type="text/javascript">
                $(document).ready(function() {
                    // prepare the data
                    var source =
                            {
                                datatype: "jsonp",
                                datafields: [
                                    {name: 'id', type: 'string'},
                                    {name: 'name', type: 'string'},
                                    {name: 'type', type: 'string'},
                                    {name: 'seats', type: 'string'},
                                    {name: 'building', type: 'string'},
                                    {name: 'device', type: 'string'}
                                ],
                                url: "https://app.psycho.unibas.ch/raumbuchung/overview/json/",
                                 root: 'data',
                                id: 'id'
                                
                            };
                    var dataAdapter = new $.jqx.dataAdapter(source);
    
                    $("#jqxgrid").jqxGrid(
                            {
                                source: source,
                                columnsresize: true,
                                columns: [
                                    {text: 'Country Name', datafield: 'id', width: 200},
                                    {text: 'City', datafield: 'name', width: 170},
                                    {text: 'Population', datafield: 'type', width: 170},
                                    {text: 'Continent Code', datafield: 'seats', minwidth: 110},
                                    {text: 'Continent Code', datafield: 'building', minwidth: 110},
                                    {text: 'Continent Code', datafield: 'device', minwidth: 110}
                                ]
                            });
                });
            </script>
        </head>
        <body class='default'>
            <div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;">
                <div id="jqxgrid"></div>
            </div>
        </body>
    </html>

    and the data source from https://app.psycho.unibas.ch/raumbuchung/overview/json/ looks like this:
    [{"id":"1","name":"64a - 01","type":"Seminarraum","seats":"25","building":"Nebenhaus","devices":[]},{"id":"2","name":"64a - 02","type":"Seminarraum","seats":"25","building":"Nebenhaus","devices":[]},{"id":"3","name":"64a - 03","type":"Seminarraum","seats":"25","building":"Nebenhaus","devices":[]},{"id":"4","name":"64a - 04","type":"Seminarraum","seats":"25","building":"Nebenhaus","devices":[]},{"id":"5","name":"64a - 07","type":"Seminarraum","seats":"35","building":"Nebenhaus","devices":[]},{"id":"6","name":"64a - 08","type":"Seminarraum","seats":"35","building":"Nebenhaus","devices":[]},{"id":"7","name":"64a - 09","type":"Seminarraum","seats":"35","building":"Nebenhaus","devices":[]},{"id":"8","name":"Computer-Schulungsraum","type":"Computerraum","seats":"20","building":"Hinterhaus","devices":[]},{"id":"9","name":"Ecolab 1","type":"Labor","seats":"8","building":"Hinterhaus","devices":[]},{"id":"10","name":"H\u00f6rsaal 010","type":"H\u00f6rsaal","seats":"88","building":"Hinterhaus","devices":[]},{"id":"11","name":"Labor Sozialpsychologie","type":"Labor","seats":"3","building":"Nebenhaus","devices":[]},{"id":"12","name":"Labor Sozialpsychologie","type":"Therapieraum","seats":"6","building":null,"devices":[]},{"id":"13","name":"Medienbearbeitung","type":"Computerraum","seats":"2","building":"Vorderhaus","devices":[]},{"id":"14","name":"N-Lab 1 - EEG und Eyetracking","type":null,"seats":"1","building":"Vorderhaus","devices":[]},{"id":"15","name":"N-Lab 2 - Physiologie","type":null,"seats":"1","building":"Vorderhaus","devices":[]},{"id":"16","name":"N-Lab 3 - Sensorische Testungen","type":null,"seats":"2","building":"Vorderhaus","devices":[]},{"id":"17","name":"Sitzungzimmer KPE\/KPP","type":"Labor","seats":"12","building":null,"devices":[]},{"id":"18","name":"UPD Erwachsenenzimmer","type":"Therapieraum","seats":"4","building":"Vorderhaus","devices":[]},{"id":"19","name":"UPD Kinder-\/ Jugendlichenzimmer","type":"Therapieraum","seats":"4","building":"Vorderhaus","devices":[]},{"id":"20","name":"UPD Testzimmer","type":"Therapieraum","seats":"4","building":"Vorderhaus","devices":[]},{"id":"21","name":"Usability Labor","type":"Therapieraum","seats":"4","building":"Vorderhaus","devices":[]},{"id":"22","name":"Verhaltenslabor KPE","type":"Labor","seats":"4","building":"Vorderhaus","devices":[]},{"id":"23","name":"Verhaltenslabor KPE","type":"Therapieraum","seats":"9","building":"Vorderhaus","devices":[]},{"id":"24","name":"Verhaltenslabor KPE","type":"Labor","seats":"4","building":"Vorderhaus","devices":[]},{"id":"25","name":"Verhaltenslabor KPP","type":null,"seats":"4","building":"Vorderhaus","devices":[]},{"id":"26","name":"Verhaltenslabor KPP","type":null,"seats":"6","building":"Vorderhaus","devices":[]}]

    Help will be much appreciated.

    Get json from s https url (ssl) #48591

    Peter Stoev
    Keymaster

    Hi Andy,

    In order to make a JSONP call, you should also add $callback=? in your URL.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Get json from s https url (ssl) #48594

    AndySimpson
    Participant

    Hello Peter,
    you mean something like:

     url: "https://app.psycho.unibas.ch/raumbuchung/overview/json/",
                                data: {
                                    featureClass: "P",
                                    style: "full",
                                    maxRows: 50
                                },
                                formatdata: function(data) {
                                    return "my data";
                                }

    Well, it still does not work. I’m kinda new to this stuff … :-/

    Best,
    Andy

    Get json from s https url (ssl) #48596

    Peter Stoev
    Keymaster

    Hi Andy,

    No, I did not mean that. I meant that URLs for JSONP requests should have additional parameter which identifies the call as JSONP. May be, pass the function’s name on your server which handles the data request. However, it is possible your server to be not configured for handling such requests at all. May be you will find this topic helpful: http://en.wikipedia.org/wiki/Same_origin_policy

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Get json from s https url (ssl) #48597

    AndySimpson
    Participant

    Thanks Peter, I’ll read this and speak with the webadmin if it’s even possible. He might have missed to configure the server properly so I can use jsonp. I’ll report back as soon as I have figured it out.

    Get json from s https url (ssl) #53521

    AndySimpson
    Participant

    For future visitors: I did a work around using curl by downloading the file to the server and then access it locally via json:

     <?php
            $ch = curl_init();
            $source = "https://app.psycho.unibas.ch/raumbuchung/index/abjson"; // url for the json from the https server
            curl_setopt($ch, CURLOPT_URL, $source);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $data = curl_exec($ch);
            curl_close($ch);
    
            $file = fopen("abjson.json", "w+"); //save it locally as abjson.json, make it writable!
            fputs($file, $data);
            fclose($file);
            ?>

    Then use

     var source =
                            {
                               [...]
                                url: "abjson.json",
                               
                            };
Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.