Abhinaya Pandey
Abhinaya Pandey

Reputation: 67

How to pass a JavaScript array object to Lasso script and fetch it to a lasso variable?

I am trying to pass javascript array from jquery ajax call to lasso script but while trying to access it in lasso script it returns null records.

I am sure I have missed something in code but unable to figure out what it is. Can anybody help me with that. Here are my code snippets.

The ajax request:

var url='https://www.zipcodeapi.com/rest/'+apikey+'/radius.json/'+zip+'/'+radius+'/'+unit;


if(zip.length == 5 && /^[0-9]+$/.test(zip)){
    var zips=new Array();

        $.ajax({
                url:url,
                dataType:'json',
                success:function(data){
                    console.log(data);
                    $.each(data,function(key,val){
                        $.each(val,function(k,v){
                            zips.push(v.zip_code);
                        });
                    }); 

                    $.ajax({
                        url:'query.lasso',
                        dataType:'json',
                        type:'post',
                        data:{zipcodes:zips},
                        success:function(data){
                        console.log(data);
                            $.each(data,function(k,v){

                            });

                        }
                    });

                }
        });
    }

The lasso query:

local(zips=json_decode(web_request->param('zipcodes')))

#zips

Upvotes: 1

Views: 166

Answers (1)

jolle
jolle

Reputation: 133

I think you need to look for web_request -> poststring

Try something like this:

local(
    posted      = json_decode(web_request -> poststring) or map,
    zips        = #posted -> find('zipcodes')
)

Upvotes: 1

Related Questions