PHP文件对字符串URL无效

时间:2018-11-15 00:02:56

标签: javascript php jquery xml

我对ajax和jquery还是很陌生,所以对不起标题,我不知道该如何表达我的问题。

我的URL字符串发送有问题:我进行了Form设置,允许用户输入货币详细信息,如下所示,一旦按下了提交按钮,我希望发送数据到PHP文件中,同时页面不会重定向,并将发送的内容作为XML放在下面的文本区域中。

我让JQuery发送字符串(很多数据我都不想发送操作或文本区域),但是PHP文件对数据没有任何作用

这是我的代码和屏幕截图:
Form

  <form name="myform"   id="myform" method="get">

 <input type="radio" name="operation" value="1" id="Post" 
onclick="displayFunctionPost()"> Post
 <input type="radio" name="operation" value="2" id="Put" 
onclick="displayFunctionPut()"> Put
 <input type="radio" name="operation" value="3" id="Delete" 
 onclick="displayFunctionDelete()"> Delete
 <br>
 Currency Code:
   <br>

    <input type="text" name="currencycode" id="currencycode" 
placeholder="Code" disabled>
    <!--currency form-->
    <br>
    Currency Name
    <br>
    <input type="text" name= "currencyname" id="currencyname" 
  placeholder="name" disabled>
   <br>
   <!---rates form--->  
    Rate(£=1):
    <br>
    <input type="number" name="rate" id="rate" placeholder="rate" disabled>
  <!---countries form-->
    <br>
   Countries (comma separated if 1+)
   <br>
    <input type="text" name= "countries" id="countries" placeholder="countries" disabled>
<br>

 <!---xml response--->
   <br>
   Response Message:
   <br>
   <div id="textarea"><textarea id="textarea" cols="70" rows="5"></textarea> 
</div>

   <input type="Submit" name="Submit" id="Submit" value="Submit" >

</form>

这是我到目前为止拥有的JQuery:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

    <script>
        $(document).ready(function() {

        $("#Submit").click(function(e){
        e.preventDefault()
         var data = "&currencyname="+currencyname+"&currencycode="+currencycode+"&rate="+rate+"&countries=";
   var data = $('#myform').serialize();


   $.ajax({
    type:    'get',
    cache:    false,
    url:      'currPut.php',
    data:     data,
    processData: false, 
    contentType: false,
    success:  function( data ) {
      alert('test ');      
    }

  });

        }); 
        });
    </script>

这是PHP文件:

 <?php


@date_default_timezone_set("GMT"); 
$xml=new DomDocument("1.0","UTF-8");
$xml->formatOutput=true;
$xml->preserveWhiteSpace=false;
$xml->load('rates.xml');

if(!$xml)
 {
   $currencies=$xml->createElement("currencies");
  $xml->appendChild($currencies);
}
 else
 {
  $currencies=$xml->firstChild;
}

 if (isset($_GET['Submit']))
  {
    $curcode = $_GET['currency-code'];
    $newrate = $_GET['rate'];
    $cname = $_GET['currency-name'];
    $countries = $_GET['countries'];
    $today = date("F j,g:i a");   

    $curr=$xml->createElement("currency");
    $currencies->appendChild($curr);


    $currate=$xml->createElement("code",$curcode);
    $curr->appendChild($currate);
    $currate->setAttribute("rate",$newrate);


    $name=$xml->createElement("cname",$cname);
    $curr->appendChild($name);

    $places=$xml->createElement("cntry",$countries);
    $curr->appendChild($places);


    $xml->save('rates.xml');




 }
 ?>

This is the form

And this is the console

0 个答案:

没有答案