mukul
mukul

Reputation: 5

ajax is not called through jquery

here is my code , Jquery is not worked when call in .js file and ajax is not called in that file

Here is my .js file :

function insertData(idvalue)
   $.ajax({
    url: "setsimilar.do",
    type: "get",
    data: {setvalues : queryid},
    dataType: "JSON",
    success: function(data) {   

                alert('Successful');    
            }   
        },
        error: function(data) {
            alert('No Record Found: '+data);
        }   
   });

Upvotes: 0

Views: 57

Answers (2)

cracker
cracker

Reputation: 4906

Try Like

       $.ajax({
               url: "URL",
                type: "GET",
                contentType: "application/json;charset=utf-8",
                data: {setvalues : queryid},
                dataType: "json",
                success: function (response) {
                    alert(response);
                },

                error: function (x, e) {
                    alert('Failed');
                    alert(x.responseText);
                    alert(x.status);
                }
            });

OR

$.get("demo_test.asp",function(data,status){
    alert("Data: " + data + "\nStatus: " + status);
});

Upvotes: 0

Afzaal Ahmad Zeeshan
Afzaal Ahmad Zeeshan

Reputation: 15860

success: function(data) {   

            alert('Successful');    
        }   
    },

Would be minimized to

success: function(data) {   

            alert('Successful');
    },

Because you were having an extra } in the success event, that was causing a Syntax error in your code.

So, your whole code would look like something like this

function insertData(idvalue) { // this bracket!
  $.ajax({
    url: "setsimilar.do",
    type: "get",
    data: {setvalues : queryid},
    dataType: "JSON",
    success: function(data) {   
      alert('Successful');
    },
    error: function(data) {
      alert('No Record Found: '+data);
    }   
  });
} // and this one! :)

Upvotes: 2

Related Questions