jQuery的发送和显示每个文本区域的行AJAX结果文本、区域、结果、jQuery

由网友(草莓不美)分享简介:我有文字area.In文本区域用户的形式可以每行输入关键字。I have the form with text area.In the text area user can enter keywords per line.我想做的事情是这样的。点击按钮发送Ajax请求到服务器后,并获得第一keyword.Then显...

我有文字area.In文本区域用户的形式可以每行输入关键字。

I have the form with text area.In the text area user can enter keywords per line.

我想做的事情是这样的。 点击按钮发送Ajax请求到服务器后,并获得第一keyword.Then显示结果/追加it.After的完成了第二keyword.Like第二发送Ajax请求这每每个关键字。

I want to do like this. After click the button send ajax request to the server and get result of the first keyword.Then display/append it.After that finished send second ajax request for 2nd keyword.Like this for per each keyword.

我想这样做,因为服务器的响应有点慢每keyword.If显示所有关键字的输出一旦被收到太多的时间看到的结果。因此,在上面的方法,我认为用户没有必要等待看到所有results.User可以通过一个关键字输出中看到的。

I want to do this because of server response is little slow per keyword.If display all keyword output at once that is getting too many time to see the result. So in above method I think user no need to wait for see the all results.User can see one by one keyword output.

我的code是这样的,我在这个词preSS采用这种plugin.Get结果为 JSON

My code is like this and I'm using this in the wordpress plugin.Get result as json.

jQuery(document).ready(function () {

 jQuery('#get_seo_rank').click(function() {  

    var keywordLines = jQuery('#keywords').val().split(/n/); 
    var current = 0;
    var total = keywordLines.length;


    for (var i=0; i < total; i++) {
            jQuery.ajax({
              type : "post",
              dataType : "json",
              url : process.php,
              data : {
                        action: "get_rank", 
                        keywords: keywordLines[i]
                    },

                  beforeSend:function(){

                  },
                  success:function(response){

                        if(response.type == "success") {
                           jQuery("#resultWrap").append(response.result);
                        }
                        else if(response.type == "error") {
                           jQuery("#resultWrap").html(response.result);

                        } else {
                             jQuery("#resultWrap").html(response.result);
                        }

                  },
                  error:function(response){

                  }


           }); 

    }  // end loop


}); // end click event

});

如果有人能帮助对本那会真的AP preciate。

If anyone can help regarding this that would really appreciate.

非常感谢你!

推荐答案

创建一个嵌套的Ajax调用函数的动态关键字: -

Create a nested ajax call function for dynamic keyword:-

将所有的数组中的关键字,让假设keyword_list和存储 VAR key_length = keyword_list.length

然后使用迭代函数来调用列表: -

Then use an iterative function to call the list:-

函数nestedAjaxCalls(ARRAY1,长度1){ //终止codition     如果(长度1 == 0){返回;}     其他{         $阿贾克斯({         ....         数据:{行动:get_rank,关键词:keywordLines [array1.length - 长度1]},         成功:函数(响应){             ...             nestedAjaxCalls(ARRAY1,长度1 -1);             }         });     } }

function nestedAjaxCalls(array1 , length1){ //terminating codition if (length1 == 0){ return;} else{ $.ajax({ .... data:{action: "get_rank",keywords: keywordLines[array1.length - length1]}, success:function(response){ ... nestedAjaxCalls(array1,length1 -1); } }); } }

当事件触发调用此函数nestedAjaxCalls(keyword_list,key_length)

When the event is triggered call this function nestedAjaxCalls(keyword_list, key_length)

阅读全文

相关推荐

最新文章