简体   繁体   中英

jquery callback with php… just want the value, not redirect

I thought this was going to be rather simple but I'm a bit rusty.

I call this javascript/jquery code:

$.get("plugin.php", {up_vote:surl},
    function(data){
    //alert(data);
    document.getElementById('numvotes').innerHTML = data;
});
......

And when it returns I get the value, which is some number that is returned as a string, then right after the number a long text about redirecting is displayed. How do I get rid of that? I just want the value. Here is what is returned: 8 (if you are not redirected after 10 seconds, please click here)

What is causing this to redirect? Or, how do I just get rid of that '(if you are ....) text?

It is actually your plugin.php sending the redirect text (and probably some other html too). Try to browse directly to plugin.php?up_vote=surl and you'll see what happens.

Furthermore, if you are using jquery anyway, why not change document.getElementById() to:

$('#numvotes').html(data);

You could try using

data = data.match(/^\d{1,}/);  
$('#numvotes').html(data);

if the result is always going to be in the same format that you gave in your question.

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