开发者

.ajax to get back different values in different groups

开发者 https://www.devze.com 2023-02-25 06:15 出处:网络
now I\'m sending an AJAX call using jQuery .ajax to a .php file that is getting all the values from the database, to process on it then send it back through different .ajax sent to different .php to u

now I'm sending an AJAX call using jQuery .ajax to a .php file that is getting all the values from the database, to process on it then send it back through different .ajax sent to different .php to update the database.

Now I'm doing this by getting all the data from the database then .split

    var result = data.split('&');

that's ok , but there is many different types of data that is hard to recognize on one group, is there a way to get more than one group of data for example like.

success: function(data,values) {
    var results = data.split('&');
    var allvalues = values.split('&');

because there is another problem that the number of certain groups of data is not fi开发者_运维百科xed. and this will be a problem when trying to select one value from all the values when they are all in one group.

I'm sorry I know I'm not so clear but this is the best I can do in explaining the problem, thanks in advance.


Better you can use JSON datatype

create json array at serverside

{"data":{"val1":"value","val2":"value"},"value":{"val1":"value","val2":"value"}}

There is a tutorial to understand JSON

http://secretgeek.net/json_3mins.asp

Then You can retrieve it simply

success:function(response){
response.data[0].val1
response.data[0].val2
response.value[0].val2
response.value[0].val2
}  


You can try out JSON datatype and send a array from php

success: function(json) {
    var results = json.data1.split('&');
    var allvalues = json.data2.split('&');
0

精彩评论

暂无评论...
验证码 换一张
取 消