// Creating variables to hold data from textboxes. First building associated details
myData.Token = $("#token").val();
myData.BuildingDisplay = $("#BuildingDisplay").val();
myData.FeatureID = $("#FeatureID").val();
myData.BuildingID = $("#BuildingID").val();
myData.Address = $("#Address").val();
myData.City = $("#City").val();
myData.District = $("#District").val();
myData.Location = $("#Location").val();
myData.State = $("#State").val();
myData.StreetName = $("#StreetName").val();
myData.Zip = $("#Zip").val();
myData.X = $("#X").val();
myData.Y = $("#Y").val();
$.ajax({
type: "POST",
url: "proxyCheck.php",
data: "{ 'Token': '" + mytoken + "','Address': '" + myaddress + "', 'City': '" + mycity + "','Location': '" + mylocation + "','State': '" + mystate + "', 'StreetName': '" + mystreetname + "', 'Zip': '" + myzip + "', 'X': '" + myX + "', 'Y': '" + myY + "'}",
contentType: "application/json;charset=utf-8",
dataType: "json",
async: false,
success: function (response) {
alert("Record has been added successfully.");
window.location.reload();
}
});
When above data is formatted into JSON object, it is presented in the following format:
{data:
{
"token":"73264280-be3f-4f5b",
"BuildingDisplay":"Fire Station 21 Fairburn - 19 East Broad St.",
"CallerEmail":"Jim.Parker@yahoo.com",
"CallerFax":"",
"CallerFirstName":"Jim",
"CallerLastName":"Parker",
"CallerMiddleInitial":"",
"CallerOtherPhone":"",
"CallerState":"",
"CallerWorkPhone":"918-354-2874"}}
What I would like to do is pass them to proxyCheck.php in the following:
proxyCheck.php?data={data:
{
"token":"73264280-be3f-4f5b",
"BuildingDisplay":"Fire Station 21 Fairburn - 19 East Broad St.",
"CallerEmail":"Jim.Parker@yahoo.com",
"CallerFax":"",
"CallerFirstName":"Jim",
"CallerLastName":"Parker",
"CallerMiddleInitial":"",
"CallerOtherPhone":"",
"CallerState":"",
"CallerWorkPhone":"918-354-2874"}}&token=73264280-be3f-4f5b
Please notice &token=73264280-be3f-4f5b
I can't seem to figure out how to do this.
Can someone please help?
$.ajax({
type: "POST",
url: "proxyCheck.php?token=" + myData.Token,
data: JSON.stringify(myData)
contentType: "application/json;charset=utf-8",
dataType: "json",
async: false,
success: function (response) {
alert("Record has been added successfully.");
window.location.reload();
}
});
return false;
}
//proxyCheck.php
<?php
$ch = curl_init("http://domain/UserServices/Create");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $_POST);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output
?>
//*******************
//AJAX
var uname = $("#user").val();
var upass = $("#pass").val();
$.post("proxyValidate.php",
{ data: JSON.stringify({ LoginName: uname,Password: upass }) })
.done(function(data) {
var result = JSON.parse(data);
switch(result.Status) {
case 0:
//login successful
tokenVal = result.Value.Token;
location.href = "http://domain/userService.php?token="+tokenVal;
break;
case 2:
//invalid login
alert(result.Message);
break;
}
})
.fail(function() {
alert("The AJAX request failed!");
});
});
//proxyValidate
<?php
$ch = curl_init("http://domain/Validation/Validate");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $_POST);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output
?>