jQuery发布到外部php

编程入门 行业动态 更新时间:2024-10-26 04:22:14
本文介绍了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("www.site/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

本文发布于:2023-10-12 01:18:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483348.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jQuery   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!