处理Ajax Jquery中的结果类型 [英] Handle Result Type in Ajax Jquery

查看:92
本文介绍了处理Ajax Jquery中的结果类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Ajax调用从Jquery调用一个动作,如下所示.

I am calling an action from Jquery by Ajax call like below.

$.ajax({
    url : "SendSMS",
    data : data,
    dataType : 'json',
    contentType : 'application/json',
    type : 'POST',
    async : true,
    success : function(res) {
        setMessage(res.stat);
    }
});

由于登录凭据,将不允许执行该操作.因此,它应该重新定向到登录页面.但这不是重定向.但是,当我直接在URL中访问操作时,我将被重定向到登录页面.

Because of login credentials it will not allow the action. So it should re-direct to login page. But It is not redirecting. But when I access the action directly in the URL I am getting redirected to login page.

http://localhost:8080/SMS/sendSMS

如何使用jQuery处理此问题?

How can I handle this with jQuery?

推荐答案

尝试一下:

  $.ajax({
    url : "SendSMS",
    data : data,
    dataType : 'json',
    contentType : 'application/json',
    type : 'POST'
  }).done(function(res, textStatus, jqXHR )
      setMessage(res.stat);
  }).fail(function( jqXHR, textStatus, errorThrown ) {
    if ( jqXHR.status=="403" ) {
      location.replace("login.php");
    }
  });

这篇关于处理Ajax Jquery中的结果类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆