약간의 도움이 필요하다. 누군가가 나를 도울 수 있기를 바란다. =) 내가 확실히하고 싶은 것은 할 수 있지만 잘못하고있다. Ajax 호출을 사용할 때 XML 파일. 다음 코드 (합성 됨)가 있습니다.SimpleXML과 JQuery Ajax를 사용하여 서버에 XML 파일 만들기
HTML을
<html>
<head>
<!-- JQuery 1.7 included -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<p>Create XML on server!</p>
<form id="prog" method="POST">
<input type="text" id="test" />
<button id="submit" type="submit"> Create now! </button>
</form>
<script>
jQuery.noConflict();
jQuery(document).ready(function($){
var test = $('#test').val();
// When the button it's clicked:
$('#submit').click(function() {
$.ajax({
// Este es el archivo PHP que procesa la información y envía el mail
url: "createXML.php",
type: "POST",
data: test,
success: function (html) {
// If succeed
if (html==1) {
alert("DONE!!");
}
}
});
});
// With this I cancel the default behaviour of the button so it doesn't submit by itself.
return false;
});
</script>
</body>
</html>
PHP를 서버
<?php
echo "HI! Ajax arrived here and this code it's being executed!";
//I load a string to be the contents of the XML file
$exemel = simplexml_load_string('<example><simple>As simple as this!</simple></example>');
// I save the file as following:
$exemel->asXml('xml/DONE.xml');
echo 1;
?>
에 PHP 코드가 작동이 예에서와 같이 : 그것은 예시하는 그냥,이 예제는 작동하지 않습니다 어쩌면 있습니다 , 다른 하나는 아닙니다. 그러나 Ajax 호출이 작동하는 내 코드의 모든 맥락에서 XML 코드를 작성하는 데 필요한 모든 기능을 수행하므로 의심의 여지가 없습니다. 내가 콘솔에서 내가
php createXML.php
XML을 할 경우 ... 아약스가 생성 아니에요 파일을 호출 할이 성공적으로 만들어지는 파일의 경우 , 등 여기에 아주 같은 PHP 코드를 가졌어요. 따라서 PHP 코드가 아니며 동시에 Ajax 호출에서 오류가 발생하지 않습니다. 왜냐하면 모든 일을해야하기 때문입니다. 무엇이 일어날 수 있 었는가 ??? 확실하게 나는 무엇인가 놓치고있다, 고맙다! =)
편집 : 나는이 작업을 수행하는 서버의 PHP 파일에서 내 실제 코드에서 :
createXML() 함수 내 이전 코드가 포함 된$test = (isset($_GET['test'])) ? $_GET['test'] : null;
//If something fails, I add the error to an errors array:
$errors = array();
isset($errors);
if (!$test) $errors[count($errors)] = 'Something failed with the test!';
//If there are any errors
if (!$errors) {
createXML();
}
.
나는 더 많은 것을하지만 가능한 한 단순화하려고 노력 중입니다. 파일 작성 여부를 확인하는 유용한 방법, "코드 작성에 실패했습니다"파일을 생성하지 못했습니다. PHP로 콘솔에서 Ajax없이 직접 실행하면 왜 잘 실행됩니까? 귀하의 도움에 감사드립니다 =) – Metafaniel