How to use type: “POST” in jsonp ajax call

后端 未结 6 2160
半阙折子戏
半阙折子戏 2020-11-22 13:11

I am using JQuery ajax jsonp. I have got below JQuery Code:

 $.ajax({  
        type:\"GET\",        
        url: \"Login.aspx\",  // Send          


        
6条回答
  •  悲哀的现实
    2020-11-22 14:01

    Use json in dataType and send like this:

        $.ajax({
            url: "your url which return json",
            type: "POST",
            crossDomain: true,
            data: data,
            dataType: "json",
            success:function(result){
                alert(JSON.stringify(result));
            },
            error:function(xhr,status,error){
                alert(status);
            }
        });
    

    and put this lines in your server side file:

    if PHP:

    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: POST');
    header('Access-Control-Max-Age: 1000');
    

    if java:

    response.addHeader( "Access-Control-Allow-Origin", "*" ); 
    response.addHeader( "Access-Control-Allow-Methods", "POST" ); 
    response.addHeader( "Access-Control-Max-Age", "1000" );
    

提交回复
热议问题