Cliff,
Thanks for the insight,

{{extend 'layout.html'}}

<h2>Get Current Running Config</h2>
Choose a Device Name<br>
<form>
<select id="q" name = "q" 
onchange="ajax('{{=URL('get_config_details')}}',['q'],'target');">
    <option value="">- Select -</option>
{{for tmp_name,tmp_id in zip(names,id):}}
    <option value="{{=tmp_id}}">{{=tmp_name}}</option>";
{{pass}}
</select>
</form>
<br/>
<div id="target"></div>

def get_device_conf():
    import requests
    import json
    url = "https://10.10.10.10/api/";
    object_type = "devices/index"
    data = requests.get(url + object_type, verify=False, auth=('admin', 
'admin'))
    json_input = data.text
    try:
        decoded = json.loads(json_input)
        names = [entry['DeviceName'] for entry in decoded['devices']]
        id = [entry['DeviceID'] for entry in decoded['devices']]

        return dict(names=names, id=id)

    except (ValueError, KeyError, TypeError):
        return "JSON format error"

On Friday, September 26, 2014 3:47:08 PM UTC-6, Cliff Kachinske wrote:
>
> First thing, read up on the ajax functionality in Web2py. It's way simpler 
> than jQuery ajax and will work just fine for what you want to do.l
>
> Consider using the ":eval" target in Web2py ajax. It will allow you to 
> send JavaScript snippets back to the server. That way you can do things 
> like this on the server side:
>
> Function get_config_details():
>     try:
>         # Your code goes here
>         return "$('#resultip').html(data);
>     except:
>         return "$('.flash').text('Server has experienced an error. Please 
> refresh the page.');"
>
>
> Also:
>
> What does the url going back to the server look like? 
>
> It should be something like 
> http://localhost/application/controller/function
>
> Use the network tab in Firebug or Chrome developer tools to watch the 
> conversation between browser and host.
>
> Your JavaScript looks OK to me except I'm suspicious about that url. Or 
> maybe your Web2py code is raising an exception.
>
> On Thursday, September 25, 2014 11:07:43 AM UTC-4, Sif Baksh wrote:
>>
>> I have this script that I've used with PHP and it works, but I'm moving 
>> everything from PHP to Web2PY easy to deploy to coworkers.
>>
>> PHP page (I left out the PHP part of the code that makes a REST API call 
>> to an appliance)
>>
>> <html lang="en">
>> <head>
>>     <meta charset="utf-8" />
>>     <title>Get Current Running Config</title>
>>     <script src="
>> https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
>> "></script>
>> </head>
>> <body>
>> <h2>Get Current Running Config</h2>
>> Choose a Device Name<br>
>> <select name="selectFrequency" id="selectFrequency">
>>   <option value="">- Select -</option>
>> <?php foreach ($json_a['devices'] as $devname)
>> {
>>  echo "<option value=". $devname['DeviceID'].">". $devname['DeviceName'] 
>> ."</option>";
>>
>> } ?>
>> </select>
>> <div id="resultip"></div>
>> <script>
>> $(document).ready(function(){
>> $("#selectFrequency").change(function() {
>>     var selected = $(this).val();
>>     $.ajax({
>>         url: "get.php", 
>>         type: "GET", 
>>         data: {id : selected},
>>         success: function(data) {
>>           $('#resultip').html(data);
>>         }
>>     });
>> });
>> });
>> </script>
>> </body>
>> </html>
>>
>> Here is my view page:
>> Enter code here...<html lang="en">
>> <head>
>>     <meta charset="utf-8" />
>>     <title>Get Current Running Config</title>
>>     <script src="
>> https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
>> "></script>
>> </head>
>> <body>
>> <h2>Get Current Running Config</h2>
>> Choose a Device Name<br>
>> <select name="selectFrequency" id="selectFrequency">
>>     <option value="">- Select -</option>
>> {{for tmp_name,tmp_id in zip(names,id):}}
>>     <option value="{{=tmp_id}}">{{=tmp_name}}</option>";
>> {{pass}}
>> </select>
>> <div id="resultip"></div>
>> <script>
>> $(document).ready(function(){
>> $("#selectFrequency").change(function() {
>>     var selected = $(this).val();
>>     $.ajax({
>>         url: "get_config_details",
>>         type: "GET",
>>         data: {id : selected},
>>         success: function(data) {
>>           $('#resultip').html(data);
>>         }
>>     });
>> });
>> });
>> </script>
>> </body>
>> </html>
>>
>>
>> I get the drop down populated correctly with all the device names.
>> But when I select a device name it calls get_config_details with ?id=43 
>>  I changed it using the inspect element in the browser to 
>> get_config_details/43 still nothing shows up on the page.
>> Any advice or am I approaching this incorrectly
>>
>> Thanks in advance
>> Sif
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to