خرید بک لینک
The problem: Send JSON to PHP that contains 5 parameters for a query. This works fine. However, the returned JSON has the original parameters plus the results of the query. This then causes an issue in the JS as the extra 5 items at the top of the file are not supposed to be there.

The JS code is as follows (the respond code I added to use it as a debug. This is how I found the extra items in the JSON):

Code:

var days = new Array(mon,tue,wed,thu,fri);

var xmlhttp;

if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
}
               
var myJsonString = JSON.stringify(days);
xmlhttp.onreadystatechange = respond;
xmlhttp.open("POST", "grid_mow_data.php", true);
xmlhttp.send(myJsonString);

function respond() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById('result').ierHTML = xmlhttp.responseText;}
}

The PHP CODE for the JSON:
PHP Code:

$str_json file_get_contents('php://input'); 
$weekdates json_decode($str_jsontrue);

$MON $weekdates[0];
$TUE $weekdates[1];
$WED $weekdates[2];
$THU $weekdates[3];
$FRI $weekdates[4];

echo 
'
<div align="center">
<td> <center> '
.$MON.'</center></td>
<td> <center> '
.$TUE.'</center></td>
<td> <center> '
.$WED.'</center></td>
<td> <center> '
.$THU.'</center></td>
<td> <center> '
.$FRI.'</center></td>
'
;


$query =  "call FSS.GetWeeklySched_2('$MON', '$TUE', '$WED', '$THU', '$FRI')"

The JSON over has values like this: 2015-06-01, 2015-06-02, 2015-06-03, 2015-06-04, 2015-06-05

My expectation is that the return JSON would only have the query results. However, it has the above parameters plus the query results.

I tried cleaning out the first five elements but that that did not work. There is still something left in the file that makes the response not work

The code for the return is as follows:
PHP Code:

$query =  "call FSS.GetWeeklySched_2('$MON', '$TUE', '$WED', '$THU', '$FRI')"

$result $mysqli->prepare($query);
$result->execute();
$result->bind_result($Name$MEALS1$ENS1$MEALS2$ENS2$MEALS3$ENS3$MEALS4$ENS4$MEALS5$ENS5);

while (
$result->fetch())
    {
    
$orders[] = array(
        
'Name' => $Name,
        
'M1' => $MEALS1,
        
'E1' => $ENS1,
        
'M2' => $MEALS2,
        
'E2' => $ENS2,    
        
'M3' => $MEALS3,
        
'E3' => $ENS3,
        
'M4' => $MEALS4,
        
'E4' => $ENS4,
        
'M5' => $MEALS5,
        
'E5' => $ENS5                
    
);
    }
        
echo 
json_encode($orders);
$result->close();
$mysqli->close(); 

Sorry for the long post. I've been fighting this for days now. Any help will be greatly appreciated.

برچسب: نویسنده: آیلین رضوانی تاريخ: سه شنبه 20 تير 1396 ساعت: 4:56

صفحه بندی