Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: b.replace is not a function

Hi I am getting an uncaught type error in ajax file in console, even though everything is working properly...

the html is

<div id="deletepropertybutton"><a href = "editproperty.php?property_id=<?php echo $data['property_id'];?>" class="editpropertybutton">Edit</a></div>

the php is

$del_id = ($_POST['del_id']);

$delete = $con->prepare("DELETE FROM tbl_property WHERE property_id='$del_id'");
$delete->execute();

$delete2 = $con->prepare("DELETE FROM tbl_favorite_properties WHERE favorite_properties_property_id='$del_id'");
$delete2->execute();

and ajax is

$(document).ready(function()
{
    $('.deletepropertybutton').click(function()
    {
        event.preventDefault();
        var del_id = $(this).attr('id');
        var $ele = $(this).parent().parent();
        $.ajax(
        {
            type: 'POST',
            url: '../controllers/deleteproperty.php',
            data:
            {
                del_id: del_id
            },
            success: function(data)
            {
                $.ajax(
                {
                    type: 'POST',
                    url: "../controllers/managepropertiesajax.php",
                    success: function(data3)
                    {
                        $('#propertycounter').html("(" + data3 + ")");
                    }
                });
                $ele.fadeOut(1000).delay(1000).remove(1000);
            }
        });
    });
});

how should i go about fixing this kind of error.. i am having this in other ajax files also the full error code is

Uncaught TypeError: b.replace is not a function

at Function.ga.matchesSelector (jquery.js:2)
at Function.r.filter (jquery.js:2)
at Ia (jquery.js:3)
at r.fn.init.remove (jquery.js:3)
at Object.success (deletepropertyajax.js:27)
at i (jquery.js:2)
at Object.fireWith [as resolveWith] (jquery.js:2)
at A (jquery.js:4)
at XMLHttpRequest.<anonymous> (jquery.js:4)
like image 998
DragonFire Avatar asked Feb 25 '17 22:02

DragonFire


People also ask

Why string replace is not working in Javascript?

The "replace is not a function" error occurs when we call the replace() method on a value that is not of type string . To solve the error, convert the value to a string using the toString() method before calling the replace() method.

What does uncaught TypeError mean?

Educative Answers Team. According to the Mozilla website for developer documents, “the TypeError object represents an error when a value is not of the expected type.” Uncaught means that the error was not caught in the catch part of the try-catch block.

Is not function jQuery?

on if not a function" jQuery error occurs for 2 main reasons: Loading an old version of the jQuery library that doesn't support the on function. Loading a library that overrides the value of the dollar sign $ variable.


1 Answers

Here is the docs to jQuery.remove.

In the docs it sais that remove expects an optional parameter which is a selector. Since you are calling it with a delay 1000 (number), jQuery excpects a selector (string) which is causing the problem (numbers don't have a function called replace).

Remove the parameter of remove like this:

$ele.fadeOut(1000)
    .delay(1000)
    .remove();     // no parameter for remove

If you want to keep the fadeout effect use the callback (second optional parameter to fadeout) like this:

$ele.fadeOut(1000, function() {
    $ele.remove();
});
like image 55
ibrahim mahrir Avatar answered Sep 30 '22 06:09

ibrahim mahrir