Jump to content

gw1500se

Members
  • Posts

    1,033
  • Joined

  • Last visited

  • Days Won

    17

Everything posted by gw1500se

  1. I'm a bit confused about regexp in Javascript. If I have a string that is in the form of a regexp do I need to create a regexp object to use it? If so do I just do: expr=new RegExp(str); TIA.
  2. Yep. There you go. It is a permissions error or wrong password for root or root is the wrong MySQL user for that database.
  3. Then it must be a permissions issue resulting from the change. Check the httpd/error log.
  4. You need to show your code but off hand I would say that there is no database named 'phplogin'. I'm guessing that is a table name and the database itself is named something else.
  5. You need to post your code. What did you try? What error did you get or what did you get that was not expected?
  6. This appears to be related to special restrictions imposed by Chrome extensions. I've moved to stackoverflow for help.
  7. Are you trying to get 3 levels deep? myArr[0][0][0]
  8. That is the entire script and no, I am not getting an error. The big difference is that my code is running as a Chrome extension.
  9. Except that didn't work either originally.
  10. If your conditional fails then that variable is not set. You only set it in the else clause. You need to initialize it to something or test if it exists before using it.
  11. Now that I have another issue fixed, I am back to the problem of no cookie being written. This is my current code: function create_cookie(obj=null) { var json_array=[]; if (obj==null) { json_array=[{none:true}]; } else { json_array=obj; } Cookies.set("Auto_Select_0519669",JSON.stringify(json_array),{expires:3650}); } var json_str=Cookies.get("Auto_Select_051969"); if (typeof(json_str)=="undefined") { create_cookie(); json_str=[{none:true}]; console.log("set new cookie"); } console.log(json_str); Each time I run this code I get the output "set new cookie". When I search for the cookie it it not found. Apparently 'Cookies.set' is not writing the cookie but I get no errors.
  12. I finally got it working but I can't explain how/why. I did: console.log(typeof(json_str)=="undefined"); The output was "true" which I expected. I then edited the line by changing 'console.log' to 'if' and changed the ';' to '{' and the thing started to work.
  13. Yes. With or without the parens, I get the same result.
  14. I an trying to determine if a cookie exists using the following code: const json_str=Cookies.get("Auto_Select_051969"); if (!(json_str in window)) { create_cookie(); json_str=Cookies.get("Auto_Select_051969"); } json=JSON.parse(json_str); When it gets to the parse I get the error: Uncaught SyntaxError: "undefined" is not valid JSON at JSON.parse (<anonymous>) at cookie_mgmt.js:16:11 'create_cookie()' is not executed. If 'json_str' is undefined, per the error, how can it fail the 'if' test? I also tried: if (typeof(json_str)=="undefined") { Which also fails the 'if' test.
  15. Deleted for now.
  16. Using that library, at least the way I read it, does not work. This is my function which produces "undefined" in the console log (no errors): function create_cookie(obj=null) { var json_array=[]; if (obj==null) { json_array=[{filter:false}]; } else { json_array=obj; } Cookies.set("Auto_Select_0519669",JSON.stringify(json_array),{expires:2147483647}); } console.log(Cookies.get("Auto_Select_0519669"));
  17. I have to let my javascript ignorance show here. It seems that package required 'imports'. Since I am writing a Chrome extension, imports are not permitted. I need the js file(s) themselves and I don't see that in the git tree.
  18. I don't know if I have a mental block or if the documentation is just poor. In any case I am trying to create a cookie with this code: const daysToExpire = new Date(2147483647 * 1000).toUTCString(); document.cookie=escape("Auto_Select_0519669="+JSON.stringify(json_array)+";expires="+daysToExpire+";"); Nothing is written. What am I dong wrong or not doing? TIA.
  19. Yes, really. Those never showed up in any of my searches. Thanks for the links.
  20. I can't find this documented any where but what responses are available other than json? I have this function: function requests(url) { return fetch(url).catch(function(error) { return(null); }) .then(function(response) { if (response==null) { return(null); } else if (!response.ok) { console.log("caught error: "+response.status); } try { return response.json(); } catch(e) { return resonse.html(); } }); } The response can be either json or html. When html results I get an error: VM13:1 Uncaught (in promise) SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON How do I tell the difference since try/catch doesn't work? TIA.
  21. Close but I'm still getting an error in the console. Maybe it doesn't matter but I can't seem to eliminate or catch this error: /projects/3U8PAUGKO25K6476BGLE7U090QYNCN/tasks/accept_random.json?ref=w_pl_prvw projects/3U8PAUGKO25K6476BGLE7U090QYNCN/tasks/accept_random.json?ref=w_pl_prvw:1 Failed to load resource: net::ERR_FILE_NOT_FOUND Is that simply not possible and there is not way to suppress it. Otherwise everything seems to be working.
  22. I'm getting the error and catching it. I don't want the error thrown. Here is my code: function requests(url) { return fetch(url).catch(function(error) { console.log("caught error: "+error); }) .then(function(response) { if (!response.ok) { throw new Error(`Request failed with status ${response.status}`); } return response.json(); }); } async function myExtension() { const data = await requests("https://worker.mturk.com/projects.json"); for (let item of data.results) { console.log(item.accept_project_task_url); const data = await requests(item.accept_project_task_url); console.log(data); break; } } myExtension(); This is the console result: /projects/3YATNUOYWPGCVB7NH3IDJB44X40R53/tasks/accept_random.json?ref=w_pl_prvw projects/3YATNUOYWPGCVB7NH3IDJB44X40R53/tasks/accept_random.json?ref=w_pl_prvw:1 Failed to load resource: net::ERR_FILE_NOT_FOUND auto_select.js:3 caught error: TypeError: Failed to fetch auto_select.js:6 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'ok') at auto_select.js:6:21 at async myExtension (auto_select.js:17:20) Only the bold line is what I expected to show up so I can handle it. Is there a coding error that is causing the rest?
  23. Yes, this is an external web site. I'll give that a try. They sure don't make this intuitively obvious.
  24. The problem is that response.ok is true even with that error. I don't understand why unless the error is being thrown by 'fetch(url)' rather than 'function(response)'.
  25. I have the following script that does a fetch: function requests(url) { return fetch(url).then(function(response) { if (!response.ok) { throw new Error(`Request failed with status ${response.status}`); } return response.json(); }); } There is one error that is occasionally expected: Failed to load resource: net::ERR_FILE_NOT_FOUND I need to handle that error and return something that indicates it to an async calling function. If I understand the code the error is coming from fetch(url) not function(response). I think I need to add a .catch somewhere to handle that error, right? As an aside, will function(response) ever really return a false for response.ok?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.