jQuery发布到外部php [英] Jquery Post to external php

查看:87
本文介绍了jQuery发布到外部php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发布到外部php文件并获取结果.它是我在线托管在服务器中的php.我想要由ajax在我的本地主机帖子中添加静态页面,并将html加载到div中.但是我无法做到这一点.

I want to post to an external php file and get the result. It a php that i have hosted in my server online. I want the static page in my localhost post by ajax and load the html in a div. But I'm not able to do this.

$.post("http://www.site.com/index.php", { font: "panchami", input: "hi" } );

这有什么问题吗?

推荐答案

JavaScript不允许跨域请求

您可以做的是服务器上的一个PHP文件,该文件读取另一个网站的内容:

What you can do is a PHP file on your server that reads the contents of the other site:

<?php echo file_get_contents($_REQUEST['url']); ?>

然后向您的文件发出请求,如下所示:

Then make requests to your file, like so:

$.post("proxy.php?url=external_url", ...);

这篇关于jQuery发布到外部php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆