Home > Web Front-end > JS Tutorial > A quick solution to ajax returning object Object

A quick solution to ajax returning object Object

亚连
Release: 2018-05-23 14:06:14
Original
3352 people have browsed it

Below I will bring you a quick solution to ajax returning object Object. Let me share it with you now and give it as a reference for everyone.

Phenomenon: Use ajax to send a request. Because the background PHP uses Alibaba’s SMS, the return type is object Object. When you see it on the browser, the return format is like this: {msg:90,ok:ok} [1,#98978]. Ajax return values ​​are difficult to handle. {msg:90,ok:ok} This is the return value of a third-party text message and cannot be removed. [1,#98978]This is the return value that you need to use in your background.

If the return type is complex and only returns one field, you can use complete to accept the callback function. data.responseText will return the result as String, and then intercept the string.

Solution:

<span style="white-space:pre">	</span>$.ajax({ 
          type : "post", //提交方式 
          url : "../ss.php",//路径 
          async:true,
          dataType:"json", 
          data : { 
            "xxs":xx,
            "xx":xx,
            "xx":xx
          },//数据,这里使用的是Json格式进行传输 
          complete: function(data) {//返回数据根据结果进行相应的处理,无论请求成功还是失败,都会走这个方法的 
          	var str=data.responseText;//将返回结果转成字符串,此时,以后台的标记“#”(自己定义,主要是截取字符串所用)为主
          	if(str.indexOf("#")>0){
          		var do=str.substr(str.indexOf("#")+1,18);
          		window.location="xx.php?xx="+dd;
          	}else{
          		alert("保存失败,请稍后重试");
          	}
          } 
        }); //ajax_end
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Introduction to the 4 common request methods of ajax in jQuery

How to use native ajax to process json strings

Let’s talk about our views and understanding of Ajax form submission

The above is the detailed content of A quick solution to ajax returning object Object. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template