JSONStore.add(数据).then()。失败的一个小问题()
函数/**
* Console output:
*
* Array 'a' in insert method after inserting x: [4, 6, 7, 8]
* Array 'a' in main method after insert has been called: [4, 6, 7]
*/
package chapter14Test;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
public class Chapter14Test
{
public static void insert(int[] a, int n, int x)
{
//declare variables
List<Integer> aList = new ArrayList<Integer>();
Integer[] tempA = new Integer[a.length + 1];
//traverse a and add values to aList
for (int i = 0; i < a.length; i++)
{
//add a value to aList
aList.add(a[i]);
} //end for
//traverse aList until n + 1 is reached
for (int i = 0; i < n; i++)
{
//determine if aList value is greater than x
if (aList.get(i).intValue() >= x)
{
//add x at index i
aList.add(i, x);
//exit loop
i = n + 1;
} //end if
} //end if
//determine if x needs to be added at the end
if (x > aList.get(aList.size() - 1).intValue())
{
//add x to end of aList
aList.add(x);
} //end if
//convert aList to an array
tempA = aList.toArray(new Integer[0]);
//reinitialize a
a = new int[tempA.length];
//transfer tempA values to a
for (int i = 0; i < tempA.length; i++)
{
//transfer value at tempA element to a element
a[i] = tempA[i].intValue();
} //end for
//display a
System.out.println("Array 'a' in insert method after inserting x: " + Arrays.toString(a));
} //insert
public static void main(String[] args)
{
//declare array
int[] a = new int[] {4, 6, 7};
//insert 8 among the first two elements in a
insert(a, 2, 5);
//display a
System.out.println("Array 'a' in main method after insert has been called: " + Arrays.toString(a));
} //main
}
运行并返回成功。函数initialiserBD()
不会返回成功。当然,它是函数WL.JSONStore.get()。add()。then()。fail()
对象&#34; errorObject&#34;发送错误:-50 PERSISTENT_STORE_NOT_OPEN
remplireBD()
&#13;
答案 0 :(得分:0)
我认为你的问题是双重的......
var collectionName="Personnes" ;
)initialiserBD
和remplireBD
,而不是在remplireBD
的成功回调中调用initialiserBD
,这可能是.get()
导致在init()
完成之前尝试Here is the button that executes the PHP code:
<input type="submit" name="submit" value="SUBMIT QUIZ" id="btn4">
Here is the PHP code that is executed:
<?php
if (isset($_POST['submit'])) {
$items = array(); $j=0;
foreach($_POST['response'] as $key => $value) {
{$items[$j++] = $value;}
if($correctAnswerArray[$key] == $value) {
$rightAnswer++;
} else {
$wrongAnswer++;
}
}
$quizScore = ($rightAnswer / (4))*100;
$query1 = "UPDATE users SET quiz1_q1 = '$items[0]', quiz1_q2 = '$items[1]', quiz1_score = '$quizScore' WHERE userid = '" . $_SESSION['userid'] . "'";
$resultt = $conn->query($query1);
if($resultt)
{ echo "Your quiz has been saved"; }
else
{ echo '<h1>System Error</h1>'; }
?>
<script type="text/javascript">
var obj = <?php echo json_encode($items); ?>;
var objj = <?php echo json_encode($correctAnswerArray); ?>;
var objjj = <?php echo json_encode($quizScore); ?>;
makeRequest(obj, objj, objjj);
</script>
<?php } ?>
*Here is the makeRequest function (under the HEAD section)*
<script type="text/javascript">
function makeRequest(obj, objj, objjj) {
$.ajax( {
type: "POST",
cache: false,
url: "quiz_results.php",
data: {resulta:JSON.stringify(obj), resultb:JSON.stringify(objj), resultc:JSON.stringify(objjj)},
success: function(results){
document.getElementById("content").innerHTML = results;
}
});
};
</script>
...