jQuery .Ajax() function selector , store specific data in variable

Posted by user279321 on Stack Overflow See other posts from Stack Overflow or by user279321
Published on 2010-02-23T10:04:56Z Indexed on 2010/04/01 19:43 UTC
Read the original article Hit count: 482

Filed under:
|
|
|

I am new to jQuery and I have the following problem.

My project has say 2 pages, 1.JSP and 2.html. Now I want to pick selected data from 2.html and use it on 1.JSP. Now this was achieved very easily using .load but I want the data to be present in a JavaScript variable rather than put it on the page (div tags, etc.), so that I can work upon that data (modify or add to database).

I tried using .ajax and was able to write the following code:

    var value = (function () {
        var val = nulll;
        var filename = " 2.html";

        $.ajax ({
            'async': false,
            'global': false,
            'url': filename,
            'success' : function(data) {
                val = data;
            }
        })
        return val;
    })()
    document.write(value)

Where do I put the selector format (say div.id5) so that my variable have only relevant data rather than the full file data?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript