Can I call error: function() on specific condition met inside of success: function(data)?
Date : March 29 2020, 07:55 AM
I hope this helps . You can't. (see first comment). And trust me, you don't want to. The error callback is meant for errors related to the ajax request and not for errors only you consider errors (i.e. nonsense data which is valid json/xml/whatever or an empty resultset). However, if you want your error function called, create it as a regular (named) function instead of an anonymous one and call it manually when your criteria are met. Note that making your function a regular one results in it not being a closure anymore - but without seeing your full $.ajax(...); call and some surrounding code it's impossible to tell if that'll be a problem or not.
|
Coding style - call method on a pointer after NULL check inside if condition
Date : March 29 2020, 07:55 AM
hope this fix your issue First, if (ptr) doesn't check whether a pointer is intialised or not, it checks if it isn't NULL. You can initialize a pointer to NULL and the condition wouldn't hold. Second, there are two cases to be treated: if ( ptr )
{
ptr->foo();
//...
}
else
{
//...
}
if ( ptr && ptr->foo() )
if ( !ptr )
throw std::exception("WTF! This shouldn't be NULL");
|
PHP Call Function from Inside Itself Until Condition Met
Tag : php , By : mediafarm
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I have a function that I am creating that basically connects to the Google Plus API and Pulls information. Unfortunately in order to get more than a few results at a time you need to use the nextPageToken provided in the API callback. Here is what I have so far: , I was able to solve it with help from Lawrence above: function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function parseResults($nextPageToken = "", $count) {
$content = get_data('https://www.googleapis.com/plus/v1/activities?query=%23throughglass&maxResults=10&orderBy=recent&fields=items(actor(displayName%2Curl)%2Cid%2Cobject(actor%2Cattachments)%2Curl%2Cverb)%2CnextPageToken&pageToken=' . $nextPageToken . '&key={YOUR_API_KEY}');
$posts = json_decode($content);
$token = $posts->nextPageToken;
foreach ($posts->items as $value){
$id = $value->id;
$name = $value->actor->displayName;
$profile = $value->actor->url;
$post = $value->url;
$post_text = $value->object->attachments[0]->displayName;
$image_small = $value->object->attachments[0]->image->url;
$image_full = $value->object->attachments[0]->fullImage->url;
$id_query = mysql_query("SELECT id FROM images WHERE id = '$id'");
if (mysql_num_rows($id_query) > 0) continue;
if ($value->verb != "post") continue;
if ($value->object->attachments[0]->image->url == "" || $value->object->attachments[0]->fullImage->url == "") continue;
if ($post_text != "#throughglass") continue;
mysql_query("INSERT INTO images (id,
author_name,
author_url,
post_url,
post_text,
image_small,
image_full) VALUES (
'$id',
'$name',
'$profile',
'$post',
'$post_text',
'$image_small',
'$image_full')");
echo "<b>ID: </b>" . $id . "<br />";
echo "<b>Name: </b>" . $value->actor->displayName . "<br />";
echo "<b>Profile URL: </b>" . $value->actor->url . "<br />";
echo "<b>Post URL: </b>" . $value->url . "<br />";
echo "<b>Post Text: </b>" . $value->object->attachments[0]->displayName . "<br />";
echo "<b>Image Small: </b>" . $value->object->attachments[0]->image->url . "<br />";
echo "<b>Image Full: </b>" . $value->object->attachments[0]->fullImage->url . "<br /><br />";
$count++;
}
if ($count < 100){
parseResults($token, $count);
}else{
echo "<br /><br /><br />" . $token;
break;
}
}
parseResults("", 0);
|
For what reason would someone call the condition to call a function inside the function?
Date : March 29 2020, 07:55 AM
With these it helps Your question is a bit hard to understand because it seems like you are using pseudo code to describe your problem. But I'll give it a stab anyway. 1 void the_function(int a) {
2 if(a) {
3 // do stuff here
4 return; }
5 return; }
|
Call a function inside a if condition
Date : March 29 2020, 07:55 AM
like below fixes the issue Hi guys i am trying to move my if condition code inside another new function and i would like to call that in my another function how can i do that , You need to change function code like below:- public function personalAgendaSortationStatuses($gridType,$finalFilters) //pass parameter
{
if (self::GRID_LIST_STATUS_AGENDA === $gridType) {
// Personal agenda sortation of statuses
unset($finalFilters['statusId']['distinct']);
$finalFilters['statusId']['values'] = [
BAS_Shared_Model_Ticket::STATUS_REPLY_RELATION => 'relation reply',
BAS_Shared_Model_Ticket::STATUS_REMINDER => 'followup',
BAS_Shared_Model_Ticket::STATUS_NEW => 'new',
BAS_Shared_Model_Ticket::STATUS_IN_PROGRESS => 'in progress',
BAS_Shared_Model_Ticket::STATUS_REOPEN => 'reopened',
];
return $finalFilters;
}
}
$statuses = $this->personalAgendaSortationStatuses(self::GRID_LIST_STATUS_AGENDA,$finalFilters);//send second parameter too
|