I add a button that has a onclick() function and this function just read value of two text_input and call an function in back end and transfer this two value as paramters. When I just load this page. Console has a error which is:
Uncaught TypeError: Cannot read property ‘addEventListener’ of null
Another error appears when I click button:
Uncaught (in promise) Error: Unable to handle the request.
My code is like this:
export function generatelkbutton_click ( event ) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
$w ( "#waringtext" ). text = "" ;
**let** orderid = $w ( "#orderidfield" ). value ;
**let** emailadd = $w ( "#emailaddfield" ). value ;
**let** parameter = orderid + "," + emailadd ;
checkEmailandOrderId ( parameter ). then ( **function** ( result ){
...
}
}
One thing is that in preview I am a member of website while I was a vistor in published version.
You’ll need to provide more information. What else are you doing on this page? Share any relevant code. What does the checkEmailandOrderId() function look like?
Keep in mind that the wix-users API is only partially functional in Preview mode. When you are in the Editor, you are also “logged in” to your site when it’s run in Preview.
I am sorry to raise up such abstract question. Now I find it is because database query in backend which is a part of function called by button. When I comment all the code about database query, it works.
It only raises this erro “Uncaught (in promise) Error: Unable to handle the request” when I click button in published webpage. It’s ok in previre page.
@yisrael-wix Thank you! Then the user run the backend code is Admin?
This is code for database query:
return wixData . query ( “Stores/Orders” )
. eq ( “number” , orderid )
. limit ( 1 )
. find ()
. then ( function ( results ){
if ( results . totalCount == 0 ){
return “-1” ;
} else {
let email = results . items [ 0 ]. buyerInfo . email ;
let paidDate = results . items [ 0 ]. activities [ 2 ]. timestamp ;
if ( email == emailadd ){
return 0 + “,” + paidDate ;
} else {
return “-1” ;
}
}
} );
@1054377643 Backend code is run as Admin. If your database collections have permissions for admin only, then you can use the supressAuth option. For information, look under the find() Parameters .
@1054377643 The Stores/Orders collection has Admin permissions and is read-only:
So, as I mentioned above in another comment, you probably need
supressAuth in your query. Your
find() should look something like this:
.find({ "suppressAuth": true })
It works! I must waste nuch more time without your help. Thanks so so so so much for your help.