将外部内容加载到本地主机上的服务器中

发布于 2024-11-24 02:42:56 字数 688 浏览 2 评论 0原文

我正在尝试创建一个动态加载内容的 Web 应用程序。当我这样做时,我当然想在本地进行开发,即本地主机。一些“功能”是表单,并且在发布该表单时从服务器发送电子邮件。因为我想访问服务器的电子邮件功能,所以我将该特定页面链接到服务器。但问题是没有加载。

在我下面的脚本中它可以工作,但是如果我更改注释以便我指向 iandapp.com,那么我只会得到空字符串。这是完全相同的页面,只是将其复制到服务器。

$("#support").click(function () {
    if(support_page==null){
       //$("#section2").load("http://www.iandapp.com/smic/subscription_2.php", function(data) {
       $("#section2").load("subscription_2.php", function(data) {
           support_page = data;
       });
    } 

该脚本位于主页 (index.html) 中,内容应加载到 id="section2" 的 div 中。

我知道 (support_page==null) 是真的,因为我在它停止的地方有一个断点。

请让我知道问题是什么以及如何解决它。我已经花了好几个小时试图让它发挥作用。

提前致谢!

I am trying to create a web application that loads content dynamically. When I do this, of course I want to do the development locally, i.e. localhost. Some of the "functionality" is a form and when posting that form an e-mail is sent from the server. Because I want to access the servers e-mail functionality, I am linking that specific page to the server. But the problem is that it is not loaded.

In my script below it works, but if I change the comments so I am pointing to iandapp.com, than I just get empty string. It's exactly the same page, just copied it to the server.

$("#support").click(function () {
    if(support_page==null){
       //$("#section2").load("http://www.iandapp.com/smic/subscription_2.php", function(data) {
       $("#section2").load("subscription_2.php", function(data) {
           support_page = data;
       });
    } 

The script is located inte the main page (index.html) and content should be loaded into a div with id="section2".

I know that (support_page==null) is true because I have a break point inside where it stops.

Please let me know what the probelm is and how I can fix it. I have been going on for hours trying to get this working.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

又爬满兰若 2024-12-01 02:42:57

谷歌关于

跨域ajax请求

。这在浏览器级别被禁用。客户端和服务器端都有一些方法可以避免这种情况。

google about

cross domain ajax requests

. This is disabled in the browser level. There are ways to circumvent this, both client side and server side.

つ可否回来 2024-12-01 02:42:57

这可能与跨域请求有关。您可以使用我认为的“黑客”, http:// /james.padolsey.com/javascript/cross-domain-requests-with-jquery/,但在我看来,这不值得。

您是否考虑过通过 SMTP 服务器发送?如果是这样,那么文件(发送邮件)位于本地就没有问题。

It probably has something to do with it being a cross-domain request. You could use what I consider to be a "hack", http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/, but I.M.O. it's not worth it.

Have you considered sending through an SMTP server instead? If so, you'd have no problem with the file (sending the mail) being local.

一直在等你来 2024-12-01 02:42:57

那么在服务器的 http 响应上添加适当的标头以允许跨域怎么样?

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Origin: *

And what about adding proper headers on server's http response to allow crossdomain ?

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Origin: *
埋葬我深情 2024-12-01 02:42:57

使用 .getJSON() 而不是 .load(),这个 方法支持跨域请求。您需要确保您的 PHP 脚本执行如下操作:

echo $_GET['callback'] . '(' . json_encode($results) . ')';

jQuery 会将类似 ?callback=callback0234 的内容附加到请求 url,因为它希望您在脚本执行时“调用”回调函数返回。因此脚本的输出可能类似于:

callback0234('mydata': '<p>This is my data</p>')

Use .getJSON() instead of .load(), this method supports cross-domain requests. You'll need to make sure your PHP script does something like the following:

echo $_GET['callback'] . '(' . json_encode($results) . ')';

jQuery will append something like ?callback=callback0234 to the request url because it wants you to 'call' the callback function when your script returns. So the output of your script may look something like:

callback0234('mydata': '<p>This is my data</p>')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文