0

I use jQuery Ajax to send data to server. I set post type as POST but data always get send using GET method. How to send data using Post method?

$.ajax({
        type: "POST",        
        dataType: 'jsonp',            
        url: 'http://do.convertapi.com/Web2Image/json/',
        data: {
            'CUrl':$('#txtUrl').val(),
            'OutputFormat':'png',
            'PageWidth':600,
            'ApiKey':apiKey
        },
        jsonp: "callback",
        success: function (data) {               
        if (data.Result)
        {                
            $('#imgSnapShot').attr('src','data:image/png;base64,'+data.File); 
            $('#dvStatus').text("Converted successfully!");
        }
        else {
            $('#dvStatus').text("Error: " + data.Error);
        }             
        },
        });

As Graham Clark posted, jsonp Ajax requests are always posted as GET. If I remove jsonp option I get another problem, cross domain posting error. Is there any solution for my problem?

Tomas
  • 17,551
  • 43
  • 152
  • 257

3 Answers3

1

As it a 5 year old question but still if some one finds it useful .. More recently browsers have implemented a technology called Cross-Origin Resource Sharing (CORS), that allows Ajax requests to different domains. so have to use cors instead of jsonp

Nilkamal Gotarne
  • 335
  • 5
  • 16
0

I believe jsonp is always sent with a GET request. If you need POST then use json. Check this question for details.

Community
  • 1
  • 1
Graham Clark
  • 12,886
  • 8
  • 50
  • 82
0

You can't send cross-domain requests via JSONP - it doesn't use XMLHttpRequest. See here for more information:

http://groups.google.com/group/jquery-dev/browse_thread/thread/e7eb4a23eef342fb?pli=1

pgl
  • 7,551
  • 2
  • 23
  • 31