<i id='0Ul1B'><tr id='0Ul1B'><dt id='0Ul1B'><q id='0Ul1B'><span id='0Ul1B'><b id='0Ul1B'><form id='0Ul1B'><ins id='0Ul1B'></ins><ul id='0Ul1B'></ul><sub id='0Ul1B'></sub></form><legend id='0Ul1B'></legend><bdo id='0Ul1B'><pre id='0Ul1B'><center id='0Ul1B'></center></pre></bdo></b><th id='0Ul1B'></th></span></q></dt></tr></i><div id='0Ul1B'><tfoot id='0Ul1B'></tfoot><dl id='0Ul1B'><fieldset id='0Ul1B'></fieldset></dl></div>

      <small id='0Ul1B'></small><noframes id='0Ul1B'>

      1. <legend id='0Ul1B'><style id='0Ul1B'><dir id='0Ul1B'><q id='0Ul1B'></q></dir></style></legend>
          <bdo id='0Ul1B'></bdo><ul id='0Ul1B'></ul>
      2. <tfoot id='0Ul1B'></tfoot>

        通过 Javascript 调用在 php 上获取 Ajax POST 数据

        Get Ajax POST data on php via Javascript call(通过 Javascript 调用在 php 上获取 Ajax POST 数据)

          <bdo id='Ndrc7'></bdo><ul id='Ndrc7'></ul>

          <small id='Ndrc7'></small><noframes id='Ndrc7'>

          <tfoot id='Ndrc7'></tfoot>
          <i id='Ndrc7'><tr id='Ndrc7'><dt id='Ndrc7'><q id='Ndrc7'><span id='Ndrc7'><b id='Ndrc7'><form id='Ndrc7'><ins id='Ndrc7'></ins><ul id='Ndrc7'></ul><sub id='Ndrc7'></sub></form><legend id='Ndrc7'></legend><bdo id='Ndrc7'><pre id='Ndrc7'><center id='Ndrc7'></center></pre></bdo></b><th id='Ndrc7'></th></span></q></dt></tr></i><div id='Ndrc7'><tfoot id='Ndrc7'></tfoot><dl id='Ndrc7'><fieldset id='Ndrc7'></fieldset></dl></div>
            <tbody id='Ndrc7'></tbody>

                • <legend id='Ndrc7'><style id='Ndrc7'><dir id='Ndrc7'><q id='Ndrc7'></q></dir></style></legend>
                  本文介绍了通过 Javascript 调用在 php 上获取 Ajax POST 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  首先我承认我是新手php,我在客户端使用 jquery(knockout js) &服务器端的 PHP.我的代码.

                  First I am conface that I am Newbie to php, I am using jquery(knockout js) at client side & PHP at server side. my code.

                  客户端:我正在使用 knockout js(Javascript).调用我的 PHP 服务.

                  Client side: I am using knockout js(Javascript). to call my PHP service.

                  我的代码:

                  self.VMSaveEditUserMode = function () {
                     try {
                        var params = { "ClientData": [controllerVM_.ClientID(), controllerVM_.VMList[0].ClientName(), controllerVM_.VMList[0].ShortName(), controllerVM_.VMList[0].Address(), controllerVM_.VMList[0].CreatedBy(), controllerVM_.VMList[0].CityName(), controllerVM_.VMList[0].PostalCode(), controllerVM_.VMList[0].ContactEmail(), controllerVM_.VMList[0].ContactPhone(), controllerVM_.VMList[0].IsCorporate()] };
                  
                        $.ajax({
                           type: "POST",
                           url: URL + "index.php/phpService/SaveClient/" + controllerVM_.TokenKey(),
                           data: JSON.stringify(ko.toJS(params)),
                           contentType: "application/json",
                           async: true,
                           dataType: 'json',
                           cache: false,
                           success: function (response) {
                           },
                           error: function (ErrorResponse) {
                              if (ErrorResponse.statusText == "OK") {
                              }
                              else {
                                 alert("ErrorMsg:" + ErrorResponse.statusText);
                              }
                           }
                        });
                     }
                     catch (error) {
                        alert("Catch:" + error);
                     }
                  }
                  

                  服务器端我的代码,我使用这个PHP代码连接DB.

                  Server Side My Code, I am using this PHP code to connect with DB.

                  PHP 代码:

                  public function SaveClient($userToken)
                      {   
                         $value = json_decode($Clientdata);
                         echo $value->ClientData[0];
                      }
                  

                  *我的问题*:

                  • 我不清楚如何在 PHP 中发布数据?我尝试了 $_POST[''] 方法以及更多方法.
                  • 我使用 eclipse 作为 php 框架.所以,当我发布数据时无法调试它.通常模式我可以调试我的代码.但不能从远程调试.为此我也对 php.ini 文件进行了更改.
                  • I am not clear on how to POST data in PHP ? I tried with $_POST[''] method as well as many more.
                  • I am using eclipse as a php framework. so, not able to debug it when i post the data.Normally mode i am able to debug my code.but not from remotely.for that i made changes on php.ini file also.

                  我的请求示例:

                  假设我使用:

                  for, data: params, 只是当时我的请求格式是.

                  For, data: params, only at that time my request format is.

                  ClientData%5B%5D=4&ClientData%5B%5D=kamlesh&ClientData%5B%5D=KAM&ClientData%5B%5D=Junagadh&ClientData%5B%5D=me&ClientData%5B%5D=SANTA+ROSA&ClientData%5B%5D=76220&ClientData%5B%5D=kamlesh.vadiyatar%40gmail.com&ClientData%5B%5D=9998305904&ClientData%5B%5D=false
                  

                  对于,data: JSON.stringify(ko.toJS(params)),

                  {"ClientData":["4","kamlesh","KAM","Junagadh","me","SANTA ROSA","76220","kamlesh.vadiyatar@gmail.com","9998305904",false]}
                  

                  推荐答案

                  如果我理解正确,您需要创建一个 PHP 服务,该服务能够接收来自客户端的类似 REST 的请求.

                  If I understand correctly you need to create a PHP service which is able to receive REST-like requests from client.

                  为了做到这一点,您需要访问原始 POST 数据.在 PHP 中它是这样完成的:

                  In order to do thad you need to access raw POST data. In PHP its being done like this:

                  $ClientData = file_get_contents('php://input');
                  

                  您可以在 php://input 的更多信息>包装文档.

                  You can read more about php://input in the wrappers documentation.

                  当然,从客户端发送数据需要使用 POST 方法和原始数据,即作为字符串.您可以使用 JSON.stringify() 从对象中获取字符串,您已经这样做了.

                  Of course from the client's side the data need to be sent using the POST method and as raw data, i.e. as a string. You can obtain a string from object using JSON.stringify() which you already do.

                  如果您传递一个对象,它将使用查询字符串格式由 jQuery 在内部转换为字符串.更多关于 $.ajax 的 jQuery 文档(最重要的选项是 dataprocessData).

                  If you pass an object, it will be converted to string internally by jQuery using query-string format. More on that in the jQuery documentation for $.ajax (the most importatnt options being data and processData).

                  这篇关于通过 Javascript 调用在 php 上获取 Ajax POST 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How do I pass parameters into a PHP script through a webpage?(如何通过网页将参数传递给 PHP 脚本?)
                  PHP - include a php file and also send query parameters(PHP - 包含一个 php 文件并发送查询参数)
                  Where can I read about conditionals done with quot;?quot; and quot;:quot; (colon)?(我在哪里可以阅读有关使用“?完成的条件的信息?和“:(冒号)?)
                  Accessing arrays whitout quoting the key(在不引用键的情况下访问数组)
                  What is the name for the quot;lt;lt;lt;quot; operator?(“lt;lt;lt;的名字是什么?操作员?)
                  default as first option in switch statement?(默认为 switch 语句中的第一个选项?)

                    1. <legend id='JHmDy'><style id='JHmDy'><dir id='JHmDy'><q id='JHmDy'></q></dir></style></legend>
                        <tbody id='JHmDy'></tbody>

                            <bdo id='JHmDy'></bdo><ul id='JHmDy'></ul>
                            <tfoot id='JHmDy'></tfoot>
                            <i id='JHmDy'><tr id='JHmDy'><dt id='JHmDy'><q id='JHmDy'><span id='JHmDy'><b id='JHmDy'><form id='JHmDy'><ins id='JHmDy'></ins><ul id='JHmDy'></ul><sub id='JHmDy'></sub></form><legend id='JHmDy'></legend><bdo id='JHmDy'><pre id='JHmDy'><center id='JHmDy'></center></pre></bdo></b><th id='JHmDy'></th></span></q></dt></tr></i><div id='JHmDy'><tfoot id='JHmDy'></tfoot><dl id='JHmDy'><fieldset id='JHmDy'></fieldset></dl></div>

                            <small id='JHmDy'></small><noframes id='JHmDy'>