首页 \ 问答 \ 停止执行脚本?(Stop executing a script?)

停止执行脚本?(Stop executing a script?)

我从ajax(addContent)调用php函数:

protected $output = array('success'=>0, 'message'=>'There was an error, please try again.');

public function addContent()
{
    $imgName = $this->doSomething();
    $this->doSomethingElse();

    //save imageName to DB
    $this->output['success'] = 1;
    return $output;
}

private function doSomething()
{
    if($imageOk){
       return $imageName;
    }
    else
    {
       $this->output['message'] = 'bad response';
       //how to return output?
    }

}

我已经将这些方法简化为说明目的。

如果方法'doSomething()'的输出响应错误,我怎样才能将它从addContent方法发送回ajax? 如果输出不好,我想退出脚本而不是继续执行doSomethingElse()。


I call a php function from ajax (addContent):

protected $output = array('success'=>0, 'message'=>'There was an error, please try again.');

public function addContent()
{
    $imgName = $this->doSomething();
    $this->doSomethingElse();

    //save imageName to DB
    $this->output['success'] = 1;
    return $output;
}

private function doSomething()
{
    if($imageOk){
       return $imageName;
    }
    else
    {
       $this->output['message'] = 'bad response';
       //how to return output?
    }

}

I have made the methods simple for illustrative purposes.

If the method 'doSomething()' has an output of bad response, how can I send this back from the addContent method to ajax? If the output is bad, I want to exit the script and not continue executing doSomethingElse().


原文:https://stackoverflow.com/questions/19450242
更新时间:2022-02-20 11:02

最满意答案

你需要演员吗? 您已经重写了displayDetails()方法以显示特定于混合的信息。 所以你应该只能调用它,运行时将确定要调用的正确方法。


Do you need to cast ? You've already overridden the displayDetails() method to display hybrid-specific info. So you should just be able to call this and the runtime will determine the correct method to call.

相关问答

更多
  • 检查维基百科的例子:这是非常有用的在一个高水平: class Animal: def __init__(self, name): # Constructor of the class self.name = name def talk(self): # Abstract method, defined by convention only raise NotImplementedError("Subclass must impl ...
  • 拯救的隐含转换: def valueOrNone[T](value: String)(implicit conv: String => T): Option[T] = { if (!value.equals("NA")) Option(conv(value)) else None } 这适用于您声明的所有情况。 如果要转换为范围内没有默认隐式转换的某些非标准类型,请确保提供一个: class MyCustomClass(str: String) { override def toString = ...
  • 如果你想到这个词的希腊根源,应该是显而易见的。 Poly = many:polygon = many-sided,polystyrene = many styrenes (a) ,polyglot = many languages等等。 变形=变化或形式:形态=研究生物形式,Morpheus =希腊神的梦想能够采取任何形式。 因此,多态性是在编程中为不同的底层表单(数据类型)呈现同一个接口的能力。 例如,整数和浮点是隐式多态的,因为您可以添加,减法,乘法等等,而不管类型是否不同。 它们在通常的术语中很少被认 ...
  • VGR的评论是正确的,但让我详细说明你的具体情况。 狗是动物,但动物不一定是狗。 您可以创建Dog对象并将它们作为Animal对象传递,但不是相反。 处理此问题的常用方法如下: public static void main(String args[]) { Dog dog = new Dog(); makeMeTalk(dog); } public static void makeMeTalk(Animal animal) { animal.talk(); } ...
  • 它来自希腊语“聚”(许多)和“morphe”(形式)。 一个多态对象可以采用多种形式(它可以用指向任何祖先类的指针表示)。 多态函数也可以采用多种形式(可以对实际上是不同类型的对象进行操作)。 It comes from the greek roots "poly" (many) and "morphe" (form). A polymorphic object can take on many forms (it can be represented by a pointer to any of its ...
  • Obj属于A级 所以首先你的铸造Obj是A到A,这就是为什么你得到As方法 第二次将超类A(A)转换为子类B. A不知道B Obj is of class A So first your casting Obj which is A to an A so that is why you get As methods The second time you are casting a superclass which is A to a subclass B. A doesn't know about B
  • 这不是多态的损失。 这是缺乏鸭子打字 。 当静态编译器只知道它是一个Student它不允许你调用非Student方法。 即使你知道,在运行时,它将可用java的静态分类系统说不。 其他语言有鸭子打字,不关心。 Java不是其中之一。 This is not a loss of polymorphism. This is a lack of duck typing. When the compiler, statically, only knows that it's a Student it wont al ...
  • 你需要演员吗? 您已经重写了displayDetails()方法以显示特定于混合的信息。 所以你应该只能调用它,运行时将确定要调用的正确方法。 Do you need to cast ? You've already overridden the displayDetails() method to display hybrid-specific info. So you should just be able to call this and the runtime will determine the ...
  • 如果您使用的是.NET 4,则可能存在重载和动态类型,这可能是您的替代方案。 class Program { static void Main(string[] args) { DC_A dca = new DC_A(); DC_B dcb = new DC_B(); XY xy = new XY(); xy.goo(dca); xy.goo(dcb); } } // base class public ...
  • 我不确定你对哪一部分感到困惑: 该数组必须是一系列书籍。 百科全书是一种书。 因此,一系列书籍可以包括任何类型的书籍 ,包括百科全书。 相反,一系列百科全书不能包含任何旧书,因为我们希望它们都是具有卷属性的百科全书。 第三本书是一本百科全书,你就投了它。 您可以在((Encyclopedia)books[2]).Volume = 10;的行中看到这一点((Encyclopedia)books[2]).Volume = 10; 。 这是允许的,但不一定鼓励,因为操作可能在运行时失败。 想象一下,如果你写过这个 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)