简体   繁体   English

通过XMLHttpRequest发送电子邮件没有响应

[英]sending email via XMLHttpRequest no response

I tried to manage editing the template but I'm still not able to send email, I'm creating an subscription box, here's my code so far: 我试图管理模板的编辑,但仍然无法发送电子邮件,正在创建订阅框,到目前为止,这是我的代码:

var x= document.getElementById("emailtxt").value;

var uploadFormData = new FormData();
uploadFormData.append("email", x);

var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://realfashionstreet.com/Emailme.php',true);
xhr.onload=function() {
    alert(this.status);
    if(this.status==200) {
        console.log('data sent');
    alert(xhr.responseText);
    } else {
        //alert(this.status);
        alert('Something Went Wrong, Try Again Later!');
    }
};

/*xhr.addEventListener("load", function () {
  document.getElementById('skm_LockPane').className= 'LockOff';
}, false);*/

xhr.send(uploadFormData);
return false;

}

Here's the box I'm getting : http://realfashionstreet.com 这是我收到的信箱: http : //realfashionstreet.com

It's just not showing any error or any response and also not sending email, but I think that site template doesn't allow to use php files if anyone have any other idea on how to send email using javascript… 它只是不显示任何错误或响应,也不发送电子邮件,但我认为,如果有人对如何使用javascript发送电子邮件有任何其他想法,则该网站模板不允许使用php文件…

Thanks 谢谢

You can't for security reasons. 您不能出于安全原因。 See the same origin policy for JavaScript. 请参见JavaScript的相同来源策略。

There are some workarounds that exploit browser bugs or corner cases, but using them is not recommended. 有一些变通办法可以利用浏览器的错误或极端情况,但是不建议使用它们。

The best approach is having a server-side proxy that receives Ajax requests, and in turn, sends HTTP requests to other servers. 最好的方法是让服务器端代理接收Ajax请求,然后将HTTP请求发送到其他服务器。 This should be carefully implemented by sanitizing input and whitelisting the types of requests that are sent, and the servers that are contacted. 应该通过清理输入并将发送的请求类型和联系的服务器列入白名单来仔细实现此目的。

You're missing the www. 您缺少www。 in the request, this is causing a cross domain policy violation. 在请求中,这导致违反跨域策略。 This is the error I see in the console. 这是我在控制台中看到的错误。

XMLHttpRequest cannot load http://realfashionstreet.com/Emailme.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.realfashionstreet.com' is therefore not allowed access. Default.asp:1

Ensure the URLs for the page and the XHR request have the exact same domains. 确保页面和XHR请求的URL具有完全相同的域。 Including subdomains like www 包括子域名,例如www

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM