简体   繁体   中英

Store content of jquery load() function into a variable

I want the content of my load() function to be stored into a variable so to pass it into another function. The project is to pass it as a sting to a function that creates a toast message in a webview for android phones! My code is :

$( '#lightson' ).click( function () {
            $.get( 'http://<?php echo $_SESSION['ip']?>/?2', {}, callbacka() );
            function callbacka() {

                var ua = navigator.userAgent.toLowerCase();
                var isAndroid = ua.indexOf("android") > -1;

                if(isAndroid) {

                Android.showToast("**Here I want to put my content**");

                }
                    else {

                        $('.status2').load('status2.php').delay(3000).queue(function() {
                        $('.status2').empty().dequeue();
                        });

                    }
            }
    } ); 

Can anyone help?

AHHHH!

You are running your callback immediately! Remove the () :

$.get( 'http://<?php echo $_SESSION['ip']?>/?2', {}, callbacka );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM