简体   繁体   中英

Passing values from jquery.ajax to php

I have created a script that sends post data to php via the $.ajax method

$uname = $_POST['uname'];
$pass = $_POST['pass'];
$compid = $_POST['compid'];

$queryData = array(
                    "Username"=>$uname,
                    "Password"=>$pass,
                    "CompanyID"=>$compid
       );

$result = $client->GetUserStores($queryData);

The post data is used to fill an array used to make a validation through a web service. I keep getting an error that System.FormatException Input was not in a correct format. But when i make a test php script that does this:

$uname = "user";
$pass = "password";
$compid = "99";

$queryData = array(
                    "Username"=>$uname,
                    "Password"=>$pass,
                    "CompanyID"=>$compid
       );

$result = $client->GetUserStores($queryData);

I get the data returned as expected and I am able to parse the xml response needed. Doesnt type juggling in PHP handle the number as string or integer if need be when it is placed into the array?

Here is my ajax call in case that may be of any help:

$.ajax({
      type: "GET",
      url: 'login.php',
      data:     {uname:storage.readValue('uname'),pass:storage.readValue('pass'),compid:storage.readValue('companyID')},
      success: function(data) {
        alert("success" + data);
      }
    });

Any help at all to see where I am going wrong here will be greatly appreciated!

Change your GET method to post:

$.ajax({
      type: "POST",
      url: 'login.php',
      data:     {uname:storage.readValue('uname'),pass:storage.readValue('pass'),compid:storage.readValue('companyID')},
      success: function(data) {
        alert("success" + data);
      }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM