Home  >  Article  >  Web Front-end  >  I just learned ajax. How to get the url value? A very awkward question_html/css_WEB-ITnose

I just learned ajax. How to get the url value? A very awkward question_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:12:181076browse

比如 li链接是25edfb22a4f469ecb59f1190150159c6e2956b54e8e782040db01d81d65d9c48test5db79b134e9f6b82c0b36e0489ee08edbed06894275b65c1ab86501b08a632eb

jquery   
$("li").click(function(){
$.get("test.asp",{id:x},
function(data,textStatus){
$(".div1").html(data)}
})

代码很简单,现在就是如何将url 后面id的值赋值给x ,{id:$(this).text}不行,$(this).text的值是空的,不是aaa







回复讨论(解决方案)

$("li").click(function(){
var x = $(this).find('a')[0].href.split('=')[1];
$.get("test.asp",{id:x},
function(data,textStatus){
$(".div1").html(data)}
})

试试

$("li").click( function() {    var x = $(this).find("a").attr("href");    x = x.substring(x.lastIndexOf("=") + 1);    $.get("test.asp", {id: x}, function(data) {        $(".div1").html(data);    });});

<li><a href="test.asp?id=aaa">test</a></li><script>function queryString(url , key){    var regex_str = "^.+\\?.*?\\b"+ key +"=(.*?)(?:(?=&)|$|#)"    var regex = new RegExp(regex_str,"i");    if(regex.test(url)) return RegExp.$1;    return undefined;}$("li").click(function(){    var url = $(this).children('a').attr('href');    alert(queryString(url,'id'))$.get("test.asp",{id:queryString(url,'id')},		function(data,textStatus){		$(".div1").html(data)		}  )})</script>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn