Voici mon JS:Comment utiliser dojo.xhrPost correctement?
<script>
dojo.require("dijit.form.Button");
function sendText(){
var button = dijit.byId("submitButton2");
dojo.connect(button, "onClick", function(event){
// The parameters to pass to xhrPost, the message, and the url to send it to
// Also, how to handle the return and callbacks.
var xhrArgs = {
//type: "POST",
url: "http://testjson.php",
content: dojo.toJson({key1:"value1",key2:"value2"},true),
handleAs: "text",
load: function(newContent){
dojo.byId("response2").innerHTML = newContent;
},
error: function(error){
// We'll 404 in the demo, but that's okay. We don't have a 'postIt' service on the
// docs server.
dojo.byId("response2").innerHTML = "Message posted.";
}
}
dojo.byId("response2").innerHTML = "Message being sent..."
// Call the asynchronous xhrPost
var deferred = dojo.xhrPost(xhrArgs);
});
}
dojo.ready(sendText);
</script>
Voici mon PHP:
<?php
foreach($_POST as $key => $val) echo '$_POST["'.$key.'"]='.$val.'<br />';
?>
Le problème est que rien est retourné. Si je mets content
au lieu de postData
J'ai $ _POST [0] = '{', $ _POST [1] = 'k' etc caractère par caractère, limité à 1000. C'est un gros problème.
S'il vous plaît quelqu'un peut-il me dire ce que je fais mal? J'ai obtenu ce code directement sur le site du dojo, donc ça devrait aller.
merci de répondre, – idan