开发者

.load() and send ajax form problem

I have 2 problem in jquery.

When I try to use the load function to update a specific div data, if I’ve used jquery functions in new data, the functions won’t start (until I refresh the page). I’ve fixed this problem by adding jquery.js file at the end of new div data but it seems illogic to me (even now I’ve done this but the problem is still there and I have to refresh the page).

My second problem is about sending data by AJAX, I can send data but when I send them to a page such as proc.php if there is any echoed data there I want to show them inside my current page, actually proc.php does some changes on database and then echoes a result, so i want to show that result inside ”div” as an alert.

I have to mention that I can use “load” function in success section and load proc.php file, but I don’t want to use this way for some reasons and I’m looking for some way to sho开发者_运维问答w HTML commands.


write your code inside the ready handler like

$(document).ready(function(){

//your code here

});

about the second problem if i have understood correctly

$.ajax({
 type:'GET',
 url:'proc.php ',
 success:function(data){
   $("#idOfyourDIV").html(data);
 },
 error:function(jxhr){
   console.log(jxhr.status);
   console.log('o0ps');
 }
});

jquery ajax


For your first problem, you don't need to load the jQuery library alongside every AJAX request. I'm not entirely sure what kind of javascript you have within that new HTML you're loading, but if you're talking about just having events wired up to elements within that new HTML, look into the .live() function within jQuery. It will rebind events to the new elements you've just loaded.

I'm not sure I completely understand your second question so you may need to explain a bit more. It can be taken a couple ways.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜