I am working with the following script:
<script>
$(document).ready(function(){
$('#postJson').click(function(){
// show that something is loading
$('#response').html("<b>Loading response...</b>");
/*
* 'post_receiver.php' - where you will pass the form data
* $(this).serialize() - to easily read form data
* function(data){... - data contains the response from post_receiver.php
*/
$.post('post_receiver.php', { user_id: "143", username: "ninjazhai", website: "http://codeofaninja.com/" }, function(data){
// show the response
$('#response').html(data);
}).fail(function() {
// just in case posting your form failed
alert( "Posting failed." );
});
// to prevent refreshing the whole page page
return false;
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<html>
<head>
<title>jQuery post JSON data using .post() method by codeofaninja.com</title>
</head>
<body>
<h1>jQuery post JSON data using .post() method</h1>
<div>Click the button below to get response.</div>
<!-- our form -->
<input type='button' value='Post JSON' id='postJson' />
<!-- where the response will be displayed -->
<div id='response'></div>
</body>
</html>
How can if for #postJson several other ids? I could with [id^=p] but then id are not defined.
And how can I compare that Id to use more data like
user_id: "143",
username: "ninjazhai",
website: "http://codeofaninja.com/
to not use the same script several times? like
if (#ida== #ida) {abc: "123", def: "456", ghi: "kdlkds"}
Script is from here.
Or is this a PHP job? But do I have to us the same code 100,000 times?