복붙노트

[JQUERY] Ajax 요청의 내용 유형 및 데이터 형식은 무엇입니까?

JQUERY

Ajax 요청의 내용 유형 및 데이터 형식은 무엇입니까?

해결법


  1. 1.contentType이 응용 프로그램 / JSON 그래서 당신이 보내는 데이터의 유형이다; 애플리케이션 / x-www-form-urlencoded를 그대로 캐릭터 = UTF-8은 공통이다; 문자셋 = UTF-8, 기본값입니다.

    contentType이 응용 프로그램 / JSON 그래서 당신이 보내는 데이터의 유형이다; 애플리케이션 / x-www-form-urlencoded를 그대로 캐릭터 = UTF-8은 공통이다; 문자셋 = UTF-8, 기본값입니다.

    JSON, HTML, 텍스트 등 JQuery와 성공 함수의 매개 변수를 채우는 방법을 알아 내기 위해이를 사용합니다 : 데이터 형식 서버에서 다시 기다리고있어 것입니다.

    당신이 뭔가를 게시하는 경우 :

    {"name":"John Doe"}
    

    다시 기대 :

    {"success":true}
    

    그럼 당신은해야한다 :

    var data = {"name":"John Doe"}
    $.ajax({
        dataType : "json",
        contentType: "application/json; charset=utf-8",
        data : JSON.stringify(data),
        success : function(result) {
            alert(result.success); // result is an object which is created from the returned JSON
        },
    });
    

    당신은 다음을 기대하는 경우 :

    <div>SUCCESS!!!</div>
    

    그럼 당신은해야한다 :

    var data = {"name":"John Doe"}
    $.ajax({
        dataType : "html",
        contentType: "application/json; charset=utf-8",
        data : JSON.stringify(data),
        success : function(result) {
            jQuery("#someContainer").html(result); // result is the HTML text
        },
    });
    

    하나 더 - 당신이 게시 할 경우 :

    name=John&age=34
    

    그런 다음 데이터를 캐릭터 라인 화하고,하지 않는다 :

    var data = {"name":"John", "age": 34}
    $.ajax({
        dataType : "html",
        contentType: "application/x-www-form-urlencoded; charset=UTF-8", // this is the default value, so it's optional
        data : data,
        success : function(result) {
            jQuery("#someContainer").html(result); // result is the HTML text
        },
    });
    

  2. 2.JQuery와 문서에서 - http://api.jquery.com/jQuery.ajax/

    JQuery와 문서에서 - http://api.jquery.com/jQuery.ajax/

    당신은 contentType이 응용 프로그램 / JSON 및 데이터 형식 텍스트로가되고 싶어요 그래서 :

    $.ajax({
        type : "POST",
        url : /v1/user,
        dataType : "text",
        contentType: "application/json",
        data : dataAttribute,
        success : function() {
    
        },
        error : function(error) {
    
        }
    });
    

  3. 3.이 데이터 타입 및 contentType이 언급 거기, http://api.jquery.com/jQuery.ajax/를 참조하십시오.

    이 데이터 타입 및 contentType이 언급 거기, http://api.jquery.com/jQuery.ajax/를 참조하십시오.

    서버 종류의 데이터를 보내기 / 받기 위해 무엇을 알 수 있도록 그들은 모두 서버에 요청에 사용됩니다.

  4. from https://stackoverflow.com/questions/18701282/what-is-content-type-and-datatype-in-an-ajax-request by cc-by-sa and MIT license