Problems with bootstrap autocomplete plugin - json

Use this plugin: https://github.com/nicolasbize/magicsuggest
I'm trying load json file, but have some troubles with it.
If I try such construction :
$('#').magicSuggest({
data: 'cities.json',
ajaxConfig: {
xhrFields: {
withCredentials: true
}
}
});
get an error:
POST http://...../cities.json 405 (Method Not Allowed)
Uncaught Could not reach server
When i'm change:
ajaxConfig: { method: 'GET' }
and try to put some letters into input field got such error:
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
How can I fix this?

Related

Unexpected token S in JSON at position 0' Next auth

A teammate and I are working developing an application portal. We have the same exact code, node version and environment variables but when he logs in, he gets this error. I am able to login perfectly without any error. He was also able to login last week so at one point it was working for him.
A lot of solutions I've read about are adding code that trims or stringifies the JSON response. But it makes no sense that it works for me as it is but he would need to add code to make his work. Does anyone know why this is happening? (He has a NEXTAUTH_URL in the .env as well).
[next-auth][error][CLIENT_FETCH_ERROR]
https://next-auth.js.org/errors#client_fetch_error invalid json response body at http://localhost:3000/api/auth/session reason: Unexpected token S in JSON at position 0 {
error: {
message: 'invalid json response body at http://localhost:3000/api/auth/session reason: Unexpected token S in JSON at position 0',
stack: 'FetchError: invalid json response body at http://localhost:3000/api/auth/session reason: Unexpected token S in JSON at position 0\n'
I had the same error with next-redux-wrapper. I was implementing the old version's set up. I had this causing error:
export const getServerSideProps = wrapper.getServerSideProps(
async ({ req, params, store }) => {
const session = await getSession({ req });
if (!session) {
return {
redirect: {
destination: "/login",
permanent: false,
},
};
}
await store.dispatch(getBookingDetails(req.headers.cookie, req, params.id));
}
);
I had to change it to:
// the way how I pass callback changed
export const getServerSideProps = wrapper.getServerSideProps(
(store) =>
async ({ req, params }) => {
....rest of the code
);
I recently encountered exactly the same problem but luckily managed to settle it.
The solution is to (1) NEXT_PUBLIC_SECRET is required in .env and (2) [...nextauth].ts added with secret: process.env.NEXT_PUBLIC_SECRET.
I have the following link to thank for the above solution.
Hope it works for you too.

Uncaught SyntaxError: Unexpected token o in JSON at position 1 I have this exception but I donĀ“t know what is this

some errors on Chrome after run my jsp, I don't know what happens:
adblock-onpage-icon-cs.js:172 Uncaught ReferenceError: browser is not defined
at onScriptLoad (adblock-onpage-icon-cs.js:172)
at adblock-onpage-icon-cs.js:183globalstorage:1
Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at handleRequest (globalstorage:47)
This is the code in js but, the but I can't understand the mistake.
$(document).ready(function() {
alert("json");
$.ajax({
//connect to a Servlet
url: "ServletReportes",
type:"POST",
dataType:"json",
success: function( result ) {
console.log(result);
}
});
});
Just in case it helps someone else, the first error has nothing to do with your code. This error shows sometimes when you have the adblock extension installed on your browser.
It is often fixed just by uninstalling and installing again the extension, otherwise you can dismiss the error as should not affect your code.
The second error also does not seem an error in your code but in the response, probably the response of the ajax call not being a valid JSON format.

Capture the response of async axios call in react

async saveForm(data) {
return await axios({
method: "post",
url: FORM_PORTAL_CONTROLLER_URL + 'savemoratorium',
body: JSON.stringify(data)
}).then(res =>
this.setState({ refNo: res.data.reference }))
}
I cannot set set state which im getting from the request it gives me below error. The Post request executes perfectly. I want to capture the response and and change the state.function is inside a component. Following errors are in the console of the page and im getting a white page after this.
react_devtools_backend.js:6 TypeError: Cannot read property 'length' of undefined
react-dom.production.min.js:152 Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
Add a validation before render
// Sample 1
if(Array.isArray(refNo) && refNo.length){
//your code
}
//Sample 2
{Array.isArray(refNo) && refNo.length? customRenderFunction(): null}
I have found the root cause for this case. Its because I had a conflict with material ui node module. (makeEffect,useEffect)

uncaught exception: INVALID_TOKEN | (intermediate value).forEach is not a function with AJAX response(JSON format)

I am getting error uncaught exception: INVALID_TOKEN (intermediate value).forEach is not a function
My code is:
$('#start')
.on('click', function() {
$.getJSON('/twillio-new/token.php', {
name: $('#my-name')
.val(),
identity: $('#my-identity')
.val()
}, function(data) {
// Create the endpoint, and then initialize the main calling app
var endpoint = new Twilio.Endpoint(data.token);
$('#startDiv')
.hide();
$('#callDiv')
.show();
init(endpoint);
});
});
JSON Response:
{"name":"cool
room","identity":"test","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJlMWE3NTI4YzYyMzdiMGE0MmZlYTc0NDk2MjRlOTFiNC0xNTA3MjEwNjQyIiwiaXNzIjoiZTFhNzUyOGM2MjM3YjBhNDJmZWE3NDQ5NjI0ZTkxYjQiLCJzdWIiOiJBQzVlMTVhMDg5NjVkNWRjM2ZkOWI3YmNiOGMyM2FhMjgxIiwiZXhwIjoxNTA3MjE0MjQyLCJncmFudHMiOnsiaWRlbnRpdHkiOiJ0ZXN0IiwidmlkZW8iOnsicm9vbSI6IiRuYW1lIn19fQ.pvfGEoVripcjq588p8l3QixuVJ4sHBjMdmWa8tspTtY"}
I am generating and getting access token for Twilio Video calling api using this. Please let me know what is wrong with this code?
Which SDK do you have installed? I have seen this error when the code being used was for the incorrect SDK. Looks like the code you are using is for the version 5. Do you have version 5 installed? There have been numerous version based issues with Twilio

Unable to read error response of fb plugin share

I am using cordova-plugin-facebook4 version 1.7.4 for facebook share in my app. I got an error while sharing one post to facebook.
{errorMessage : "Facebook error: {FacebookServiceException: httpResponseCode: -1, facebookErrorCode: 190, facebookErrorType: null, message: Error validating access token: The user has not authorized application XXXXXXXX.}" }
From the facebook docs, I came to know that this error occurs when user de-authorizes my app. So I want to login again and obtain a new access token.
In the Facebook docs, I came to know that facebook sends error code 190 when this error occurs. I am able to see the facebookErrorCode field in my error response.
My problem is I am unable to parse the error response to get the facebook error code. I tried few JSON parse and JSON stringify methods. But nothing worked. I am unable to obtain the error code.
Can anyone help me in parsing the error response and getting the error code ?
UPDATE
Here is my code sample
facebookConnectPlugin.showDialog(
{ method: "share_open_graph",
action: 'og.likes',
object: JSON.stringify({
object:'https://developers.facebook.com/docs/',
})
},
function (response) {
console.log(JSON.stringify(response));
DialogService.showToast('FB_SHARE_SUCCESS', 'Short', 'Bottom');
},
function (response) {
console.log('share failed. ',response);
if(response.errorMessage.facebookErrorCode == 190){
fblogin.then(
function(response){
share();
},
function(error){
//
}
)
}else{
DialogService.showToast('FB_SHARE_FAILED', 'Short', 'Bottom');
}
}
);
I am able to post to facebook if the user authorizes the app for posting.
If the user de-authorizes, I am unable to capture the error code 190.