1

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(){

    }
});
Shaowei Ling
  • 176
  • 10
linn
  • 71
  • 2
  • 8
  • What does "not working" mean? Does the success handler fire? Does the error handler fire? Does the email get sent? Are there any errors in the JS console? When you look at the Net tab in your browser developer tools, do you see the request being sent? Is it formatted the way you would expect? What about the response? – Quentin Mar 14 '14 at 09:03

2 Answers2

0

Disable same origin policy in Chrome

Go to this link It should work after you done this It's google chrome that is doing cross domain issue

Community
  • 1
  • 1
  • That doesn't explain why the code in the question doesn't work (since the point of JSONP is to bypass the same origin policy) and the OP can't go and turn off security features in the browsers of everybody who visits their site. – Quentin Mar 14 '14 at 09:01
  • 1
    Must be adding callback at end of URL? – user3374969 Mar 14 '14 at 09:08
0

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(){
    }
});
andrewtweber
  • 20,851
  • 19
  • 78
  • 105
linn
  • 71
  • 2
  • 8