使用PHP表单跨域POST请求 [英] Form Cross domain POST request using PHP

查看:943
本文介绍了使用PHP表单跨域POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从表单数据发送到PHP文件,所以我可以将其存储在数据库中,但它不工作...

I am trying to send data from a form to a php file so I can store it in a database, but its not working...

在code的形式是不一样的服务器作为PHP文件上,因为形式将是一个移动应用程序。

The code for the form is not on the same server as the php file, because the form will be on a mobile app.

HTML

<div data-role="page" id="createclub">

<div data-role="content">
    <form id="cname" align="left" action="post">
        <label for="name">Enter Name:</label>
        <input type="text" id="name" value=""  />
        <input type="submit" value="Submit" data-inline="true">
    </form>

    <div id="result"></div>
</div>

    <script type="text/javascript">
       $(document).ready(function(){
        $("#cname").submit( function () {
        $.post(
        'http://www.clubbedin.isadcharity.org/createclub.php',
        $("#cname").serialize(),
        function(data){
        $("#result").html(data);
        alert("Data " + data);
        }
        );
        return false;
        });
        });
    </script>

php文件

php file

$name = $_POST['name'];

感谢您!

推荐答案

添加这在你的PHP文件的开头:

Add this at the beginning of your PHP file:

header("access-control-allow-origin: *");

在跨域策略更多信息<一个href="http://www.cy$p$pssnorth.com/blog/programming/cross-domain-ajax-request-with-json-response-for-iefirefoxchrome-safari-jquery/">here.

这篇关于使用PHP表单跨域POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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