Re: [web2py] (PWA) Send a Subscription information to my Server

2022-01-06 Thread Murat KAŞIKÇIOĞLU
Hi,
When you call the function from web page, it should be return something.
After that, you can call that from Javascript.
 I've created a sample function as below:

@auth.requires_login()
def getSettings():
setId = request.vars.setId
record = []
try:
record = db(db.settings.id == setId).select().first()
msg = "Found"
except:
msg = "Error or not found"

# result in json format
rbc = {"result": 0,
   "params": record["params"],
   "message": msg}
return json.dumps(rbc)


When you call the function from web, it returns a json object:

// http://192.168.0.142:8000/myapp/settings/getSettings?setId=5

{
  "result": 0,
  "params": [
{
  "opno": "11",
  "group": "Something",
  "quantity": "4",
  "id": 1617021161251,

},
{
  "opno": "13",
  "group": "Depo",
  "quantity": "1",
  "id": 1617021161253
},
"message": "Found"
}


Best regards,
Murat.


mostwanted , 6 Oca 2022 Per, 14:58 tarihinde şunu
yazdı:

> The [target] controller is " save_data ", "func" was is just a mistake I
> made
>
> On Thursday, January 6, 2022 at 10:08:43 AM UTC+2 snide...@gmail.com
> wrote:
>
>> On Tuesday, January 4, 2022 at 1:44:36 AM UTC-8 mostwanted wrote:
>>
>>> I tried adding this to my code
>>>
>>>
>>>
>>>
>>>
>>>
>>> *$.ajax({  type: "POST",  url:
>>> "https://www.sesoa.co.bw/init/default/func.html
>>> ",  data:
>>> JSON.stringify(subscribeOptions)   }).done(function( msg ) {
>>> console.log(msg);  });*
>>>
>>> when i assign *{{=URL('save_data')}}* to url: I get a 400 BAD REQUEST
>>> error
>>> When i assign *"/init/default/func.html" *to url: I get a 500 INTERNAL
>>> SERVER error
>>>
>>> I dont know what to do anymore
>>>
>>
>> Is your [target] controller function called "save_data"  or "func"?
>>
>>  For the 500 error, is a ticket generated?  If not, do you have logging
>> enabled?  500s are often the result of an exception.
>>
>> For the 400, what is the actual URL sent to the server?  Your front end
>> should have logged that.
>>
>> /dps
>>
>>
>>
>> --
> 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 web2py+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/701e76bc-5be9-4843-aa00-f30abf81a929n%40googlegroups.com
> 
> .
>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CAC5t_JxjDK7nNu-uPvXUozuL8-m8aijw75G%2BpXhtiag12djTwQ%40mail.gmail.com.


Re: [web2py] (PWA) Send a Subscription information to my Server

2022-01-06 Thread mostwanted
The [target] controller is " save_data ", "func" was is just a mistake I 
made

On Thursday, January 6, 2022 at 10:08:43 AM UTC+2 snide...@gmail.com wrote:

> On Tuesday, January 4, 2022 at 1:44:36 AM UTC-8 mostwanted wrote:
>
>> I tried adding this to my code
>>  
>>
>>
>>
>>
>>
>> *$.ajax({  type: "POST",  url: 
>> "https://www.sesoa.co.bw/init/default/func.html 
>> ",  data: 
>> JSON.stringify(subscribeOptions)   }).done(function( msg ) {  
>> console.log(msg);  });*
>>
>> when i assign *{{=URL('save_data')}}* to url: I get a 400 BAD REQUEST 
>> error
>> When i assign *"/init/default/func.html" *to url: I get a 500 INTERNAL 
>> SERVER error
>>
>> I dont know what to do anymore
>>
>
> Is your [target] controller function called "save_data"  or "func"?
>
>  For the 500 error, is a ticket generated?  If not, do you have logging 
> enabled?  500s are often the result of an exception.
>
> For the 400, what is the actual URL sent to the server?  Your front end 
> should have logged that.
>
> /dps
>
>
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/701e76bc-5be9-4843-aa00-f30abf81a929n%40googlegroups.com.


Re: [web2py] (PWA) Send a Subscription information to my Server

2022-01-06 Thread Dave S


On Tuesday, January 4, 2022 at 1:44:36 AM UTC-8 mostwanted wrote:

> I tried adding this to my code
>  
>
>
>
>
>
> *$.ajax({  type: "POST",  url: 
> "https://www.sesoa.co.bw/init/default/func.html 
> ",  data: 
> JSON.stringify(subscribeOptions)   }).done(function( msg ) {  
> console.log(msg);  });*
>
> when i assign *{{=URL('save_data')}}* to url: I get a 400 BAD REQUEST 
> error
> When i assign *"/init/default/func.html" *to url: I get a 500 INTERNAL 
> SERVER error
>
> I dont know what to do anymore
>

Is your [target] controller function called "save_data"  or "func"?

 For the 500 error, is a ticket generated?  If not, do you have logging 
enabled?  500s are often the result of an exception.

For the 400, what is the actual URL sent to the server?  Your front end 
should have logged that.

/dps



-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/ca9a422a-d895-4f5e-b252-d377ff500311n%40googlegroups.com.


Re: [web2py] (PWA) Send a Subscription information to my Server

2022-01-04 Thread mostwanted
I tried adding this to my code
 





*$.ajax({  type: "POST",  url: 
"https://www.sesoa.co.bw/init/default/func.html;,  data: 
JSON.stringify(subscribeOptions)   }).done(function( msg ) {  
console.log(msg);  });*

when i assign *{{=URL('save_data')}}* to url: I get a 400 BAD REQUEST error
When i assign *"/init/default/func.html" *to url: I get a 500 INTERNAL 
SERVER error

I dont know what to do anymore

On Monday, January 3, 2022 at 1:30:08 PM UTC+2 muratkas...@gmail.com wrote:

> Hi,
>
> Can you try to change the "body:" with "data:" on the code?
> There is a sample JS code on the page: 
> https://www.digitalocean.com/community/tutorials/submitting-ajax-forms-with-jquery
>
> By the way, it is better to check the JSON object format with 
> https://jsonlint.com/ or similar.
>
> Best,
> Murat.
>
>
> mostwanted , 3 Oca 2022 Pzt, 10:31 tarihinde şunu 
> yazdı:
>
>> Hi guys, I am still in the path of converting my app into a PWA. 
>> After subscribing the user to receive push messages I have to take save 
>> this information to the server into my database & this is where I am 
>> failing, I tried the code below to send the information to a function that 
>> will save into a database but the function is not receiving anything 
>> because i keep getting *TypeError: expected string or buffer *when i try 
>> to read the information.  Is there an easier way to grab information from 
>> JavaScript function as JSON data & send it to the server?
>>
>> *function sendSubscriptionToBackEnd(subscription) {* 
>> * method: 'POST', *
>> *url: "{{=URL(''save_data")}},*
>> * headers: { 'Content-Type': 'application/json' }, *
>> * body: JSON.stringify(subscription) }) *
>> *  .then(function(response) {*
>> *if (!response.ok) {*
>> *throw new Error('Bad status code from server.'); } return 
>> response.json(); }) .then(function(responseData) { if (!(responseData.data 
>> && responseData.data.success)) { throw new Error('Bad response from 
>> server.'); } }); }*
>>
>> Regards
>>
>> -- 
>> 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 web2py+un...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/web2py/d287bf6d-df95-47b7-ba3b-4062bc12b772n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/f1606fe4-c53c-426b-b688-336e45d423b2n%40googlegroups.com.


Re: [web2py] (PWA) Send a Subscription information to my Server

2022-01-03 Thread Murat KAŞIKÇIOĞLU
Hi,

Can you try to change the "body:" with "data:" on the code?
There is a sample JS code on the page:
https://www.digitalocean.com/community/tutorials/submitting-ajax-forms-with-jquery

By the way, it is better to check the JSON object format with
https://jsonlint.com/ or similar.

Best,
Murat.


mostwanted , 3 Oca 2022 Pzt, 10:31 tarihinde şunu
yazdı:

> Hi guys, I am still in the path of converting my app into a PWA.
> After subscribing the user to receive push messages I have to take save
> this information to the server into my database & this is where I am
> failing, I tried the code below to send the information to a function that
> will save into a database but the function is not receiving anything
> because i keep getting *TypeError: expected string or buffer *when i try
> to read the information.  Is there an easier way to grab information from
> JavaScript function as JSON data & send it to the server?
>
> *function sendSubscriptionToBackEnd(subscription) {*
> * method: 'POST', *
> *url: "{{=URL(''save_data")}},*
> * headers: { 'Content-Type': 'application/json' }, *
> * body: JSON.stringify(subscription) }) *
> *  .then(function(response) {*
> *if (!response.ok) {*
> *throw new Error('Bad status code from server.'); } return
> response.json(); }) .then(function(responseData) { if (!(responseData.data
> && responseData.data.success)) { throw new Error('Bad response from
> server.'); } }); }*
>
> Regards
>
> --
> 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 web2py+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/d287bf6d-df95-47b7-ba3b-4062bc12b772n%40googlegroups.com
> 
> .
>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CAC5t_Jy%3D1cb2cARHRV8wOdNbh04TL0W_aXnf6BY22-NxLdpwpg%40mail.gmail.com.


[web2py] (PWA) Send a Subscription information to my Server

2022-01-02 Thread mostwanted
Hi guys, I am still in the path of converting my app into a PWA. 
After subscribing the user to receive push messages I have to take save 
this information to the server into my database & this is where I am 
failing, I tried the code below to send the information to a function that 
will save into a database but the function is not receiving anything 
because i keep getting *TypeError: expected string or buffer *when i try to 
read the information.  Is there an easier way to grab information from 
JavaScript function as JSON data & send it to the server?

*function sendSubscriptionToBackEnd(subscription) {* 
* method: 'POST', *
*url: "{{=URL(''save_data")}},*
* headers: { 'Content-Type': 'application/json' }, *
* body: JSON.stringify(subscription) }) *
*  .then(function(response) {*
*if (!response.ok) {*
*throw new Error('Bad status code from server.'); } return response.json(); 
}) .then(function(responseData) { if (!(responseData.data && 
responseData.data.success)) { throw new Error('Bad response from server.'); 
} }); }*

Regards

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/d287bf6d-df95-47b7-ba3b-4062bc12b772n%40googlegroups.com.