error $.ajax({});

Discussion in 'jQuery' started by Andreit, Aug 4, 2011.

  1. #1
    i have a problem with $.ajax({});
    I have a single file js: test.js with :
    Js - 1
    
    var id_post = 2;
    $.ajax({
    	url: "test.php",
    	type:"GET",
    			
    	data:"post="+id_post,
    	success: function(msg){
    		$('.load').html(msg);
            }
    });
    
    PHP:

    In test.hp is:
    // Test.php
    <a href="" class="delete">Delete</a>
    HTML:
    And:
    Js - 2
    $(function delete() {
    	$(".delete").click(function() {
    
    		var dataString = 'test=2';
    		var parent = $(this);
    		
    		$.ajax({
    			type: "POST",
    			url: "delete.php",
    			data: dataString,
    			cache: false,
    
    			success: function(html){
    				parent.html(html);
    			}  
    		});
    		return false;
    	});
    });
    PHP:
    "Delete" function not working...
    Where is the problem?
    Thanks!
     
    Andreit, Aug 4, 2011 IP
  2. freelancewebaz

    freelancewebaz Well-Known Member

    Messages:
    976
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    145
    #2
    When you make an AJAX request to a PHP script the PHP script needs to echo back something for the javascript to receive back.
     
    freelancewebaz, Aug 4, 2011 IP
  3. Andreit

    Andreit Greenhorn

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    I do not understand. 1 example, please.
     
    Andreit, Aug 4, 2011 IP
  4. Andreit

    Andreit Greenhorn

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    $(".delete").live("click", function() {
    it works. Closed
     
    Andreit, Aug 5, 2011 IP
  5. xemsol

    xemsol Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You have to write the delete code in JS like this
    It is in this way because the when the first page load jQuery binds all the events to currently present html.
     
    xemsol, Aug 23, 2011 IP