How to open PHP page with arguments using ajax in the same windows?
I'm doing that on this way:
$.ajax({
url:'stavkenalog.php',
method:'POST',
data: {'UIDNalog':item_id },
success:function(data)
{
window.location.assign("stavkenalog.php?UIDNalog=" + item_id);
}
});
But I want to avoid sending arguments on this way:
window.location.assign("stavkenalog.php?UIDNalog=" + item_id);
Instead of this above I want to se send
data
Is that somehow possible?
</div>
I'm not exactly clear on your intent. It seems that if you're using AJAX, redirecting to the page would not be necessary.
That being said, you could use jQuery to dynamically generate a <form>
and <input>
elements and then submit the form.
var data = {
'UIDNalog': 3
};
$.ajax({
url: 'https://httpbin.org/post',
method: 'POST',
data: data,
success: function(result) {
console.log('Data: ' + JSON.stringify(data));
console.log('Got AJAX response.');
var $form = $('<form>', {
'action': 'https://httpbin.org/post',
'method': 'post',
'enctype': 'application/x-www-form-urlencoded'
});
$.each(data, function(k, v) {
jQuery('<input>', {
'type': 'hidden',
'name': k,
'value': v
}).appendTo($form);
});
console.log('Submitting in 3 seconds...');
setTimeout(function() {
$form.hide().appendTo('body').submit();
}, 3000);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</div>