0

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?

BrokenBinary
  • 7,731
  • 3
  • 43
  • 54
Andre
  • 1
  • 1
  • Have a `` and use `user_id: $(this).data("id")` – mplungjan Jun 24 '16 at 17:19
  • Perfect. This is working. With your information theres no need for further data like username: "ninjazhai", website: "http://codeofaninja.com/ ... Thank you. Or do I have to define further information like username: "ninjazhai", website: "http://codeofaninja.com/ for Ajax and/or Json? – Andre Jun 24 '16 at 18:32
  • how can I search her for ID beginning with a number: $('#response').html("Loading response..."); ? Is it: $('[id^=1]', '[id^=2]') ...., $('[id^=1]', '[id^=2]') .... or $('[id^=0-9]').... or $('[id^=1]' || '[id^=2]')....? None of them is working. And how can I set for specific IDs a delay vor maybe 3 seconds? I found something here but don't no how to setup: http://stackoverflow.com/questions/3972911/add-delay-before-sending-new-ajax-request-using-jquery. Previously I used $(this).delay(i * 300) for a delay. – Andre Jun 25 '16 at 20:16
  • Use a class to select more than one id – mplungjan Jun 25 '16 at 20:27
  • This is not working when I add it like $('classname').mouseover(function(){ this.classname = '81791433319412'; this.classname += '186291433319404'; – Andre Jun 25 '16 at 21:35

0 Answers0