Calling ajax function returned error

I have following code for ajax on html button click.

  $('#button').click(function() {
           data:  $("#data").serialize(),
           success: function(data){
            error:function(XMLHttpRequest, textStatus, errorThrown) { 
                alert("Status: " + textStatus.Message+errorThrown+XMLHttpRequest); 
                //alert("Error: " + errorThrown); 

The PHP code:

// receive data from app's http request

echo var_dump($_POST);

// write data from my webapp to a text file
file_put_contents('update.txt',$name." \n".$message);  

    $result=pg_query("UPDATE geofence  SET latitude='$latitude', longitude='$longitude', datetime='$date',         message='$message',        username='$username', radius='$radius' WHERE name='$name';");
 echo $js;
 return $js;

The ajax code calls the php code and updates the database but the success part of ajax is not called. The error function is. Why would it be doing this?


You should add

  dataType: "json"

Remove echo var_dump($_POST); and return $js; from php file.

Need Your Help

Changing cell data

php grid radphp rpcl

For a project I need to work in RadPHP XE2

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.