<script>$(function(){
$('#url').keypress(function(event) {
var v_url = $('#url').val();
if(event.which == 13 && v_url!=""){
$('#res').html("Loading...");
doajax(v_url);
}
});
function doajax(url){
$.ajax({
url: 'getdata.php',
dataType: 'json',
data: {url: url},
})
.done(function(data) {
var h3 = $('<h3>').html("Loading"),
box = $('#res').html("").append(h3);
for(var i=0;i<data.length;i++){
box
.append('<ul>')
.append("<li>"+data[i].email+"</li>")
.append("<li><a href='"+data[i].name+"'>"+data[i].lastname+"</a></li>")
.append("<ul>");
}
}).fail(function(){
$('#res').html('Error');
});
}
});
</script>
<input type="text" id="url" value="https://www.example.com<?php echo $_SERVER['REQUEST_URI']; ?>" style="width:600px;height:30px;font-size:25px">
How can i submit this input when page loads??
And the only way i can submit this input is by pressing ENTER Key.
i tried to do a button submit but it didn't work.
I am doing this because for example i enter the www.example.com/BillGates and when i enter this page url i use a php code to get the current page url so i put it in the input value, when i open the page i don't want people than to press the enter key in the input form but i want the get the results automatically on page load so they don't need to press the enter key.
well you can do this.............
$(document).ready(function(){
$("#enter_key_id").click();
});
this click your enter button at page loads................
You can't submit a input but you can submit a form:
In your PHP:
<form id="form-id" action="url.php" method="POST">
/* better hidden than text if you don't want to the user can change it */
<input type="hidden" name="url" value="http://www.example.com...<?php print $anything; ?>" />
</form>
In your JS:
$(document).ready(function() {
$('#form-id').submit();
});
But i don't understand why you need to do this. It's no better to do a curl call from the first PHP?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.