Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Jquery post return中选择元素_Javascript_Jquery_Html_Post_Userscripts - Fatal编程技术网

Javascript 从Jquery post return中选择元素

Javascript 从Jquery post return中选择元素,javascript,jquery,html,post,userscripts,Javascript,Jquery,Html,Post,Userscripts,我正在尝试从jquery post返回数据中选择一个元素。字符串正在返回,但当我尝试从返回的html字符串中选择一个元素时,选择总是空的。这是一个正在加载greasemonkey的用户脚本 refresh(); function refresh(___id,___action,___page){ $.post("http://www.example.com", {auction_id:___id,action:___action,page:___page}, funct

我正在尝试从jquery post返回数据中选择一个元素。字符串正在返回,但当我尝试从返回的html字符串中选择一个元素时,选择总是空的。这是一个正在加载greasemonkey的用户脚本

refresh();

function refresh(___id,___action,___page){
            $.post("http://www.example.com", {auction_id:___id,action:___action,page:___page}, function(bidpage){
            var auction_id = $("#auction_id", bidpage).val();
            console.log(auction_id);
});
此帖子将返回此数据

    <html><head></head><body><input type="hidden" name="auction_id" id="auction_id" value="8583949"></body></html>
但拍卖id始终为空。我找不到任何解决办法。感谢您的帮助。

这是因为您将bidpage作为字符串获取。您需要先将其转换为HTML:

var auction_id = $("#auction_id", $( bidpage ) ).val();
正如jQueryAPI应该是DOM元素、文档或jQuery

评论:

看起来像jQuery条带和元素,因此您需要使用:

var auction_id = $( bidpage ).val();

您可以尝试将post数据添加到div:

<div id="appendpostdatahere"></div>


function refresh(___id,___action,___page){
  $.post("http://www.example.com", {auction_id:___id,action:___action,page:___page}, 
    function(bidpage){
      $('#appendpostdatahere').html(bidpage);
      var auction_id = $('#auction_id).val();
      console.log(auction_id);
    });
}

似乎jQuery剥离了HTML和BODY元素,所以需要使用var auction_id=$bidpage.val;这在我的情况下是不可能的。而且我认为这个解决方案必须更有效,因为我在用秒来工作。一定很快。