Ajax returns a quick workaround for object _ajax related

Source: Internet
Author: User

Phenomenon: Use Ajax to send a request, because backstage PHP, using Ali's text message, later return type object, see in the browser is such a return format: {msg:90,ok:ok}[1, #98978]. Ajax return value is difficult to handle. {Msg:90,ok:ok} This is the third party text message return value, cannot go away. [1, #98978] This is the return value that you want to use in the background.

If the return type is complex and simply returns a field, the callback function can be accepted with complete, Data.responsetext will return the result as String, and the string can be intercepted.

Workaround:

<span style= "White-space:pre" >	</span>$.ajax ({ 
          type: "POST",//Submit as 
          URL: ".) /ss.php ",//Path 
          async:true,
          dataType:" JSON ", 
          data: { 
            " XXS ": xx,
            " xx ": xx,
            " xx ": xx
          },// Data, which is used in JSON format for transmission 
          complete:function (data) {///returns the results of the corresponding processing, regardless of the success or failure of the request, will go this way 
          	var str= data.responsetext;//will return the result to a string, at which point the background tag "#" (defined by itself, primarily to intercept the string) is the primary
          	if (Str.indexof ("#") >0) {
          		var do= Str.substr (Str.indexof ("#") +1,18);
          		window.location= "xx.php?xx=" +DD;
          	} else{
          		alert ("Save failed, try again later"); 
        //ajax_end

The above is a small series for everyone to bring Ajax back to the object of the rapid resolution of the whole content, I hope that we support cloud Habitat Community ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.