drummer392
drummer392

Reputation: 473

Creating Ajax Request

I'm fairly new to AJAX, so I was having a little trouble getting started.

Basically, I want to make an AJAX request using the GET option and have a URL such as admin/something.php?id=1&that=33 be sent to the backend which will perform my PHP functions.

How am I going to generate my data using attr like $(this).attr('id') which is basically just grabbing DIV.ID information and such?

EDIT: How could I integrate it into this sortable function?

$( ".heriyah" ).sortable({
    handle : '.handle',
    connectWith: ".heriyah",
    revert: "invalid",
    update: function(event, ui){
    if(($(ui.sender).attr('id') == undefined)&&($(this).attr('id') == ui.item.parent().attr('id'))){
         alert('UPDATE ' + $(this).attr('id') + ' ' + (ui.item.index()+1) + ' ' + $(ui.item).text()); 
    }
},

Upvotes: 0

Views: 95

Answers (2)

Zencode.dk
Zencode.dk

Reputation: 1364

jQuery does the trick very simple:

$.ajax({

    url: "admin/something.php?id=1&that=33",
    context: document.body,
    success: function(data){
        // display the return from something.php
        $("#myresult").html(data);
    }

});

Upvotes: 0

Richard Forrest
Richard Forrest

Reputation: 3616

Use jquery to generate ajax request. See documentation here.

Example code might look like this:

var request = $.ajax({
                    url: "something.php",
                    type: "GET",
                    data: {id:1,that:33} ,
                    dataType: 'json',
                    contentType: "application/json; charset=utf-8"
                });

 request.done(function (data) {
     //Put complete code here
 });

 request.fail(function (jqXHR, textStatus) {
      alert("Request failed: " + textStatus);
 });

Upvotes: 1

Related Questions