My purpose is that the value of the href attribute of the original a tag is false.
I want the user to change the value of the href attribute after clicking the a tag and lead to a link.
This link is http ://XXX.XXX.html/?key='name value in data'&tit='title value in data'.
The data passed from the data background,
contains an array [{"name":"haha","title":"123"},{"name":"haha","title": "4567"}], is such data,
Then when using ajax to transmit the data in the background, the corresponding values are combined into the form of a link, and passed to the href value of the a tag,
so that the user can When clicked, jump to the page corresponding to each a tag.
PS: I am a newbie and I don’t know much about it. The code I wrote is very problematic, but I don’t know what to do. Please help me! Kneel down and thank you!
The following is the code part:
<p class="xixi">
<a href="haha/form.html">1</a>
<a href="haha/form.html">2</a>
<a href="haha/form.html">3</a>
<a href="haha/form.html">4</a>
<a href="haha/form.html">5</a>
</p>
<script>
$.ajax({
type:"get",
url:"aaa.json",
success:function(data){
$(".xixi a").on('click','a',function(data){
for(var i = 0;i < data.length;i++){
for(var j = 0;j < data.length[i];j++){
var zName = data[i][j].name;
var zTitle = data[i][j].title;
$(this).attr('href','haha/form.html?key="+zName+"&tit="+zTitle"');
}
}
});
}
})
</script>
In addition, I have another question for you guys. I can’t see ajax in the chrome browser.
But when I checked it in firefox, no error was reported. Can I use firefox to see if ajax has any effect?
$(this).attr("href","haha/form.html?key="+zName+"&tit="+zTitle);
I feel like I wrote the wrong address. Please see if this works.
First of all, what kind of array is this [{"name":"haha","title":"123"},{"name":"Haha","title"}:"4567"], what the hell is this part? "title"}:"4567"
I really don’t quite understand what the poster meant~ I’ll just make a rough guess: the link to the a tag is obtained through ajax, and it’s not there from the beginning~ In addition, see
$
符号,我就猜楼主用的jquery
. The specific implementation of my code below should be achievable~Execute directly after the page is loaded
ajax
,获得链接后修改所有a
标签的链接。(楼主处理ajax
The result is this paragraph, the for loop, I don’t understand it very well~)Also, where can I watch ajax in chrome?
F12
打开开发者模式,然后选network
The problem of string splicing behind href is not ajax problem
[{"name":"Hehe","title":"123"},{"name":"Haha","title":"4567"}]
This is a one-dimensional array, traverse the objects in it , only one loop is needed to organize name and title