Tomas
Tomas

Reputation: 18117

Send data to server using jQuery $.ajax Post method

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?

Upvotes: 0

Views: 5382

Answers (3)

Nilkamal Gotarne
Nilkamal Gotarne

Reputation: 395

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

Upvotes: 1

Graham Clark
Graham Clark

Reputation: 12966

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

Upvotes: 0

pgl
pgl

Reputation: 7981

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

Upvotes: 0

Related Questions