jquery exit function in ajax call
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Is there a way to exit a function, depending on the result of an GET request. , I think the solution can be something like this function hi () {
$.ajax({
url: "/shop/haveItem",
type: "GET",
success: function (data) {
if (data == '1') {
ifData1();
} else {
ifDataNot1()
}
}
});
}
function ifData1 () { /* etc */ }
function ifDataNot1 () { /* etc */ }
|
Run AJAX call on page exit
Date : March 29 2020, 07:55 AM
|
Why don't I get an infinite loop when I call exit from an atexit handler?
Tag : c , By : user183526
Date : March 29 2020, 07:55 AM
seems to work fine "These callbacks must not call exit()" does not mean "If these callbacks call exit(), special interesting things will happen". It just means "don't do it, or you're on your own". It's possible that a different POSIX-compliant system will do something else, like an infinite loop. Since you didn't follow the rules, you can't count on what will happen. (I would assume that few if any systems would get into an infinite loop, though. It's trivial to avoid that, and I can't imagine it being a useful result.)
|
While Loop Won't Exit While Using Read System Call
Date : March 29 2020, 07:55 AM
will help you You should use getline() instead of read(). Because getline() does a lot of the work for you. Also, if you only wanted to receive 1 line from input, then simply use read() or getline() without the while() loop that you established. The while loop will be most necessary for multiple inputs, which is what I assumed you wanted since you are calling this a shell type program and your prompt string has sh in it. If you want to use read() in your code, then you should create your own getline() that uses read(). This could be an example of the code for your own my_getline() function code for your loop using read(), and you should add your conditionals to break as you wish. char *inputc, input[256];
int i;
for (i = 0; (read(STDIN_FILENO, inputc, 1) != EOF); i++)
{
input[i] = inputc[0];
}
$ cat main.c
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
size_t size = 256;
char prompt[5] = "sh$ ";
char *inputc = NULL;
/* print out prompt */
write(1, &prompt, 4);
while(getline(&inputc, &size, stdin) != -1)
{
/* check if input is "quit" to terminate the mini shell */
if (strncmp(inputc, "quit", 4) == 0)
break;
/* prints the input */
printf("%s", inputc);
/* re-print out prompt to continue loop*/
write(1, &prompt, 4);
}
printf("%s\n", inputc);
return 0;
}
$ gcc -Wall -Werror -Wextra -pedantic main.c
$ ./a.out
sh$ This is a test
This is a test
sh$ See how well getline works!
See how well getline works!
sh$
sh$ quit
quit
$
|
How to exit loop in an async call?
Tag : ios , By : jehammon
Date : March 29 2020, 07:55 AM
Hope that helps async function call should be avoided inside loop. Suppose checkRoom() method makes API call internally. In that case, loop will run for all rooms and API requests for all rooms would be queued regardless of when you get response for each request. Ideally you should replace loop with recursion. Call checkRoom() inside a function, let's call it mainFunction(), and wait for the response. If your criterion for joining room doesn't meet, then call your mainFunction() recursively which will make next call to checkRoom() function. Something like this: var rooms: Array<Room> = []
var currentRoomIndex: Int = 0
func mainFunction() {
checkRoom() { // async func
let room = rooms[currentRoomIndex]
if room.player.count == 1 {
join(room)
joined = true
break
} else {
currentRoomIndex += 1
mainFunction()
}
}
}
|