This time I will show you how to implement ajax to return object Object, and what are the precautions to implement ajax to return object Object. The following is a practical case, let's take a look.
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 thecallback function, data.responseText will return the result as String, and intercept the string is enough.
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
How to use native ajax to process json data
Ajax obtains API data for national weather forecast
The above is the detailed content of How to implement ajax to return object Object. For more information, please follow other related articles on the PHP Chinese website!