Jump to content
php.lv forumi

Recommended Posts

Posted

var Cpages = {
	request:function(url, div, page){
		$.ajax({ 
		  beforeSend:function(){
			  $(".ajax_loading").show();	
			  $(".pnavig_parent").hide();
		  },
		  url: url,
		  success: function(txt){
			  $(".ajax_loading").hide();
			  $(".pnavig_parent").show();
			  $(".pnavigMactive").removeClass().addClass("pnavigM");
			  $(".pnavigM a[id='" + page + "']").addClass("pnavigMactive");
			  $(div).html(txt);
		  },
		  error: function(txt){
			  $(".ajax_loading").hide();
			  $(".pnavig_parent").show();
			  $(div).html(txt);
		  }   
		});
	}
}

 

$(".pnavigM a[id=" + page + &quot]").addClass("pnavigMactive"); - es biju domājis, ka viņš pievienos to class pie pnavigM, kur tagam a id = page, bet viņš pievieno to class pie a taga. kā uztaisīt, ka viņš pievieno tam, kam biju domājis?

Posted

.js

var Comment = {  
  onCommentSubmit:function( el, url, targetEl ) {
	 var data = $(el).serialize();
	 var type = "POST";
	 Star.ajax( type, el, url, data, targetEl ); 
	 return false;
  }

}
var Star = {
 ajax:function( type, el, url, data, targetEl ) {
        $.ajax({
	type: type,
	beforeSend:function(){
		$(el).children(".button_parent").hide();
		$(el).children(".ajax_loader").show();
	},
	url: url,
	data: data,
	success:function(txt){
		$(el).children(".ajax_loader").hide();
		$(el).children(".button_parent").show();
		if(txt == "OK") {
		 loadContents(targetEl, "/p_gamma/news/rq/r_latest_comments.php?id=" + $(el).children("input[name='id']").val());
		}
	},
	error:function(txt){
		$(el).children(".ajax_loader").hide();
		$(el).children(".button_parent").show();
	}
 });

return false;
}
}

<form method="post" id="add_comment" action="/p_gamma/news/" onsubmit="Comment.onCommentSubmit(this, '/p_gamma/news/rq/p_comments.php', '#ncomment_response'); return false;">
<input name="id" type="hidden" value="<? echo $get_news['id'] ?>" />
<textarea class="textarea" cols="25" name="comment" rows="4"  onkeyup="Comment.remainingChars(this, event);"></textarea>
<input type="submit" id="submit_comment" value="Add comment" />
</form>

 

Vai kopumā pareizi js/jquery lietas? Kaut ko uzlabot, saisināt?

Bet problēma man ir šāda:

loadContents(targetEl, "/p_gamma/news/rq/r_latest_comments.php?id=" + $(el).children("input[name='id']").val());

Kā lai iegūst el (=>this => tātad formas) input, kura name=id vērtību? Man viņš atgriež undefined, jo man kaut kas smagi nesanāk ar šito: $(el).children("input[name=id]").val(), bet viss pārējais darbojas.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...