jQuery AJAX提交帮助

我有一个表单,允许用户执行搜索股票代码。数据通过PHP cURL传输到另一个URL。这很好,我们在网站上的其他几个地方。我需要能够修剪返回的数据(它返回整个页面)并且只显示数据之间的数据 {} STARTKINETICK {} ENDKINETICK  部分。 我需要将它显示在div#results中。请帮忙!这应该是这么简单!
$(document).click(function() { 
$("#SymbolSearchForm").submit(function() {
    $.ajax({
     url: "PHP/Kinetick_Symbol_Search.php",
     type: "post",
     dataType: "HTML",
      success: function(html){
        html = $.trim(html);
        html = html.match(/{STARTKINETICK}(.*){ENDKINETICK}/)[1];
        var end = "{ENDKINETICK}";
        $("#return").append(html.substring(html.indexOf("{STARTKINETICK}"), html.indexOf(end) + end.length));
    }

    });
});
});     
已邀请:
您可以使用
html.indexOf("{STARTKINETICK}")
html.indexOf("{ENDKINETICK}")
获取起点和终点,然后使用
html.substring
。不要忘记将“{STARTKINETICK}”的长度添加到起点。 编辑
var start = "{STARTKINETICK}";
html = html.substring(html.indexOf(start) + start.length, html.indexOf("{ENDKINETICK}"); 
    
你需要的正则表达式:
"foo{STARTKINETICK}myText{ENDKINETICK}bar".match(/{STARTKINETICK}(.*){ENDKINETICK}/)[1]; // returns myText
整码:
success: function(html){
    html = $.trim(html);
    html = html.match(/{STARTKINETICK}(.*){ENDKINETICK}/)[1];
    $("#return").append(html);
}
    
有点偏离主题,但是你知道jQuery有一个很好的方法 - load()异步加载html。此外,您可以传递应从结果中提取的元素选择器。如果你可以控制服务器端,你可以在
<div id="to_be_extracted"></div>
中包装{STARTKINETICK}和{ENDKINETICK}并打电话
$('#return').load('PHP/Kinetick_Symbol_Search.php #to_be_extracted');
我在这里和那里使用这种技术,发现它非常有用。     

要回复问题请先登录注册