比较ajax函数中的id并定义多个id

时间:2016-06-24 17:10:36

标签: javascript php ajax

我正在使用以下脚本:

<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>

如果#postJson有几个其他ID?我可以使用[id ^ = p],但后来没有定义id。

如何比较该ID以使用更多数据,如

user_id: "143", 
username: "ninjazhai", 
website: "http://codeofaninja.com/ 

多次不使用相同的脚本?喜欢

if (#ida== #ida) {abc: "123", def: "456", ghi: "kdlkds"}

脚本来自here

或者这是一份PHP工作吗?但是,我需要向我们提供相同的代码100,000次吗?

0 个答案:

没有答案