Jump to content

gw1500se

Members
  • Posts

    1,029
  • Joined

  • Last visited

  • Days Won

    16

Everything posted by gw1500se

  1. I think we are missing my question which is why I thought a new thread is needed. I have the data outside of the function but I don't recognize the format it is in so I don't know how to extract that array I need. The variable (hits) is typeof 'obj'.
  2. All I want to do is get that array outside of the function. The processing I need to to on it is going to be too much. Plus the function would then have to be recursive as the data within the array will require additional fetches.
  3. Time to do a reset. This may need to be a new thread. Here is my current code: async function requests(url) { const response = await fetch(url); if (!response.ok) { throw new Error(`Request failed with status ${response.status}`) } const data = await response.json(); return data.results; } console.log("Getting page data"); hits=requests("https://worker.mturk.com/projects.json").then(results => { return(results); }).catch(error => console.log("auto_select: "+error)); console.log(hits); The console log now shows this (unexpanded): \/Promise >[[Prototype]]: Promise >[[PromiseState]]: "fulfilled" >[[PromiseResult]]: Array(55) This doesn't seem like normal json but I need to get that array into a variable.
  4. I tried using your code and it seems to work. However, what I am getting is not quite what I need. It appears that 'results' shows 2 arrays. I want to put the 2nd array into a variable for processing. When I do something like 'hits=results[1]' I don't really get the same thing in the array that is logged. This is the result of the 'console.log(results)' (unexpanded): >Array(0) >Array(53) How do I put the 2nd array into a variable I can process as an array? I tried 'hits=results[1]' but I get the first element of the 2nd array.
  5. That's a confusing statement. My understanding is that the fetch returns immediately since it is an async process. This whole thing is confusing and a tough nut for me to crack.
  6. Thanks. I saw that but I can't figure out how to do that in the context of my function and how to return the value: async function requests(url) { const x=await fetch(url) .then(response => { // indicates whether the response is successful (status code 200-299) or not if (!response.ok) { throw new Error(`Request failed with status ${response.status}`) } await return response.json() }) .then(data => { console.log(data.num_results) return(data.results) }) .catch(error => console.log("Auto_select: "+error)) } var json_formatted_str, obj; console.log("Getting page data"); json_formatted_str = requests("https://worker.mturk.com/projects.json"); console.log(json_formatted_str); Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
  7. I have a function that uses fetch which is an asynchronous function. After reading on how to wait for the result I am unable to figure out how to do the wait. Here is my script: function requests(url) { fetch(url) .then(response => { // indicates whether the response is successful (status code 200-299) or not if (!response.ok) { throw new Error(`Request failed with status ${response.status}`) } return response.json() }) .then(data => { console.log(data.num_results) return(data.results) }) .catch(error => console.log("Auto_select: "+error)) } var json_formatted_str, obj; console.log("Getting page data"); json_formatted_str = requests("https://worker.mturk.com/projects.json"); console.log(json_formatted_str); Can someone help me set this function up so it does not return until the fetch completes? TIA.
  8. Hmm. I think I got was was expected: Object num_results: 55 page_number: 1 results: (55) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] total_num_results: 55 [[Prototype]]: Object
  9. Thanks for the reply. I'm not quite sure how to syntactically do that. I added console.log(data) right after the return and got nothing other than the same undefined error on data.count. I guess that means I ether cannot log it there or response is returning nothing but neither is it giving an error.
  10. I am just starting to learn to use 'fetch'. I have the following script: function requests(url) { fetch(url) .then(response => { // indicates whether the response is successful (status code 200-299) or not if (!response.ok) { throw new Error(`Request failed with status ${response.status}`) } return response.json() }) .then(data => { console.log(data.count) console.log(data.products) }) .catch(error => console.log("Auto_select: "+error)) } var json_formatted_str, obj; console.log("Getting page data"); json_formatted_str = requests("https://worker.mturk.com/projects.json"); I kind of gleaned this from an example but am not understanding what I am doing. The URL returns data in json format and I want the function to return that data so I can process it. I think it is not returning any data but simply writing it to the console. In addition, I get an undefined error on 'console.log(data.count)'. Can someone explain what this is doing and how to simply return the json data to the main code? TIA.
  11. Did you echo $_POST("club") to make sure it contains what you expect? I don't see where you are passing it in the form.
  12. Given all the information you are not providing, the best that can be said is that there is a bug in your code.
  13. You need to change the $_GET index to what you want. E.G. if (isset($_GET["poststring"} {
  14. You are trying yo use GET method but specifying POST. Use this: <form action="add-sig.php?id=<?=$contact['id']?>" method="get">
  15. Semicolons are still missing. In addition, don't use * in your query. Specify only those column you expect to use.
  16. I think you want: ssl_version=$_SERVER(SSL_PROTOCOL);
  17. This should be a simple query update. What have you tried and what doesn't work as expected? Please show the code you tried (be sure to use the code icon (<>) at the top of the menu and specify PHP for your code) along with any errors or any difference between what you get and what you expect.
  18. First please use the code icon (<>) at the top of the menu for your code and select PHP. It is not clear what you are asking. If you want the records whether of not they have the word then why is that phrase in the query? If I understand, you can check the resulting records for the word in the subject and if missing, output a zero.
  19. Do the validation with JavaScript and if OK then submit the form. Keep in mind that PHP is stateless and server side only. Once PHP outputs the page, it forgets everything and the next submit is new as far as PHP is concerned. You should re-validate with PHP in case hackers are trying to penetrate your server, in which case simply output an error page. It is more user friendly to validate with JavaScript so the user does not have to wait on the server.
  20. Did you echo $original_name to make sure it contains what you expect (you didn't show how you built it)? Do you have errors turned on? error_reporting(E_All)
  21. Did you print $ballInformation just before the execute to make sure it contains what you think?
  22. It goes in your python code. Rather than just print the data, you need to also print the other HTML tags.
×
×
  • 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.