jquery ajax调用 - 如果dataType只是一个文本(字符串),则获取返回值 [英] jquery ajax call - get returning value if dataType is simply a text (string)

查看:382
本文介绍了jquery ajax调用 - 如果dataType只是一个文本(字符串),则获取返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码。

    $.ajax({
    type: "POST",
    url:"blahblah.php",
    data: "{}",
    async: true,
    dataType: "text",
    success: function() {
       if(returning data from blahblah.php == true)
           window.location.href="http://www.blahblah.com/logout.php";
    }
}); 

1)无需发送数据。

2)文件blahblah.php进行一些处理并返回true或false。

2) File "blahblah.php" does some processing and returns either true or false.

3)我想获得响应,如果是,则重定向到另一个php页面。

3) I want to get the response and If true redirect to another php page.

我不知道如何在blahblah.php文件中读取函数的返回数据!!

I do not know how to read the returning data of the function in the blahblah.php file!!

提前谢谢你。
George

Thank you in advance. George

推荐答案

您必须将变量传递到成功打电话。

You have to pass a variable into the success call.

$.ajax({
    type: "POST",
    url:"blahblah.php",
    data: "{}",
    async: true,
    dataType: "text",
    success: function( data ) {

        console.log(data);

    }
}); 

如果成功方法运行,那么您已成功提交文件并可以使用简单的<$ c重定向$ c> document.location =http://www.example.com/somewhere.php

If the success method runs then you have successfully submitted the file and can redirect with a simple document.location = "http://www.example.com/somewhere.php

这篇关于jquery ajax调用 - 如果dataType只是一个文本(字符串),则获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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