Search code examples
phpjqueryajaxjsonp

CROSS DOMAIN ISSUE--jsonp not working


I need to access a php file from another server i.e, the server which I have doesn't support php.I need to send email from this.

I tried cross domain a server which has php and php function to send email.

I tried this using Jsonp

This is my code

var app = 'http://www.maildomain.com/mail.php';
$.ajax({
    url: app,
    async: true,
    dataType: "jsonp",
    jsonp: "jsoncallback",
    type:"POST",
    success: function(html){
         alert("aa");
    },
    error: function(){

    }
});

Solution

  • Thanks for the answers given.

    Everybody was close to the answer

    I got it anyway... it was an asynchronous parameter which was causing problem. It needed to be set false.

    This worked

    var app = 'http://www.maildomain.com/mail.php';
    $.ajax({
        url: app,
        async: false,
        dataType: "jsonp",
        jsonp: "jsoncallback",
        type:"POST",
        success: function(html){
           alert("aa");
        },
        error: function(){
        }
    });