Help Web.js
rq need help in web.js
\
INFO: 162.158.126.151:55288 - "POST /api/orders/3PE25468C5919202R/capture HTTP/1.1" 404 Not Found
the user id is never sent to the /api/order/code/capture
like supposed
12 Replies
The issue seems to be that the
userid
variable is not defined in the scope of the onApprove
function. This is why it's not being sent in the fetch request to /api/orders/${data.orderID}/capture/${userid}
.
In the createOrder
function, you've defined userid
and used it in the fetch request. However, this variable is local to the createOrder
function and is not accessible in the onApprove
function.
To fix this, you could define userid
in a scope that is accessible to both functions. Here's how you could do it:
In this updated code, userid
is defined outside of the Buttons
function, making it accessible to both createOrder
and onApprove
.
Please note that this advice is not explicitly stated in the documentation, but it's a common practice in JavaScript programming.@Deno AI Helper
I'm sorry, but I didn't see a question in your last message. Could you please ask your question again?
@Deno AI Helper
TypeError: Cannot read properties of null (reading 'getAttribute')
The error message you're seeing,
TypeError: Cannot read properties of null (reading 'getAttribute')
, typically occurs when you're trying to access a property or method (in this case, getAttribute
) on null
or undefined
.
In JavaScript, null
is a value that represents no value or no object. It is an assignment value that means "no value" or "no object". undefined
means a variable has been declared but has not yet been assigned a value.
In your case, it seems like the element you're trying to select with document.querySelector('script[data-userid]')
is returning null
. This could happen if there is no element in the document that matches the provided selector, or the script is running before the DOM is fully loaded.
To fix this issue, you can add a check to see if the element exists before trying to access its getAttribute
method:
This way, you're ensuring that element
is not null
before trying to access getAttribute
on it. If the element is not found, an error message will be logged to the console.@Kepar The error is thrown because you don't have the corresponding element on the page that the paypal script is looking for. Maybe you skipped a step in their documentation? Their code expects a
<script data-userid="some-value">
element on the page.@marvinh.
@Kepar Can you point me to the script tag with a
data-userid
attribute in your snippet?De the I'd is correctly sent yo the html I did the tests, bug seem like it can't be sent to the JavaScript
@marvinh.
Reach out to PayPal, it's an issue with their script. It's not something related to Deno
Nah,it's not PayPal, is that the JavaScript feature I added won't send the variable I want
Want me to do a drawing to show you what I mean?