简体   繁体   English

如何检查ajax请求是否由特定的URL处理原型

[英]how to check whether the ajax request handled by a specific url or not prototype

I try to use an ajax request to save a category option and wonder how could I detect whether my ajax request has been successfully handled by ajax_attributes.phtml. 我尝试使用ajax请求保存类别选项,并且想知道如何检测ajax_attributes.phtml是否成功处理了我的ajax请求。 My issue is no matter what url I specify, it always alerts it works, even I change the url into something like yadayada.phtml ,which is not existed at all. 我的问题是无论我指定什么url,它始终会发出警报,即使我将url更改为like yadayada.phtml ,也根本不存在。

 new Ajax.Request('ajax_attributes.phtml', 
            {
                parameters: {categoryId: categoryId},
                onSuccess: function(response) {
                // Handle the response content...
                alert('it works');
                },

                onFailure: function(){
                 alert('Something went wrong...');
                }
            }); 

You can try with this code : 您可以尝试使用以下代码:

var request = $.ajax({
     url: "script.php",
     type: "POST",
     data: { categoryId: categoryId},  
     dataType: "html"
}); 

request.done(function( msg ) {
     alert('it work');
});

request.fail(function( jqXHR, textStatus ) {  
     alert('Something went wrong...');
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM