Ajax 호출의 응답으로 Json 배열을 받고 있습니다.이 Json 배열 데이터를 다른 페이지에 즉시 게시하고 해당 페이지로 리디렉션하고 싶습니다. 내가 어떻게 할 수 있는지 아는 사람 있나요
$.post("flightsearch/searchhome.php",{
fromairport2 : fromairport1,
toairport2 : toairport1
}, function(data){
alert(data);
//var response = data;
//window.location.replace("flight-detail.php");
});
해당 페이지로 이동하는 응답 데이터를 게시하고 동시에 해당 페이지로 리디렉션하고 싶습니다.
을 캡처 한 후에 JSON
는 연결된 입력 필드를 사용하여 양식의 jQuery 객체를 만듭니다. 양식이 작성되면 제출하십시오. 로드하는 동안 사용자 화면에 표시되지 않도록 제거하는 것뿐입니다.
/* Bind Click Event to Button */
$('button').on('click', function() {
/* Set Empty jQuery Form Object */
var formObject = $('<form/>', { method: 'POST' });
/* Fetch JSON */
$.get('https://jsonplaceholder.typicode.com/posts/1', function(response) {
/* Itererate Through Response */
$.each(response, function(key, value) {
/* Append jQuery Input Object w/ Associated Name/Value to Form Object */
$('<input/>', { name: key, value: value }).appendTo(formObject);
});
/* Append Form Object to Body, Submit, and Remove */
formObject.appendTo('body').submit().remove();
});
});
/* Delegating Form Submission on Body to Prevent Submission to Show Console Log */
$('body').on('submit', 'form', function(event) {
event.preventDefault();
console.log($(this).serializeArray());
});
<body>
<button>Fetch JSON and POST</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</body>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다