1

I can't figure out why this is triggering the alert. The error value is undefined. add_size.php is just a simple update query and it is returning a string response. The query works fine and the record is updated. Why is the success not being triggered?

$('#size_add_btn').on('click', function(e){
    e.preventDefault();
    sizeboxvalue = $('#size_name').val();
    $.ajax({
        type: "POST",
        url: "add_size.php",
        data: {name: sizeboxvalue},
        dataType: 'text',
        success: function(text) {
            $("#sizeRow").prepend("<div class='col-lg-4'><input type='checkbox' name='attr_size[]' value='"+ text +"' > " + text + "</div>");
        },
        error:function(err){
            //handle your error
            alert('did not work ' + err + 'e: ' + e);
        }
    });
});

php file:

$name = $mysqli->real_escape_string($_REQUEST['name']);
$sql = "update attributes set size=concat(size, ',$name');";
$mysqli->query($sql);
$result->close();
echo $name;
3
  • Please post your php file, and describe more the error that you retrieve Commented Apr 20, 2015 at 20:28
  • Does your javascript console report a 500 error? Commented Apr 20, 2015 at 20:49
  • 500 (Internal Server Error) jquery.js:6send jquery.js:6x.extend.ajax jquery.js:6(anonymous function) product:751x.event.dispatch jquery.js:5v.handle Commented Apr 20, 2015 at 21:00

2 Answers 2

1

Its because the response is not text. So you should add the text header before the echo statement in the add_size.php

So the final code will looks like

$name = $mysqli->real_escape_string($_REQUEST['name']);
$sql = "update attributes set size=concat(size, ',$name');";
$mysqli->query($sql);
//$result->close();
header("Content-type: text/xml");
echo $name;
Sign up to request clarification or add additional context in comments.

5 Comments

That did not help. Still get the alert triggered.
It updates the database record fine. err is "undefined" and so is e
can u tell me what is the response in the console.not the alert.
sorry, I posted the console reply in my previous replies to others.
500 (Internal Server Error) jquery.js:6send jquery.js:6x.extend.ajax jquery.js:6(anonymous function) product:751x.event.dispatch jquery.js:5v.handle
0

the problem was the line

$result->close();

in the php file. There was no $result! Why is it always so obvious?!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.