0

I'm trying to use ajax to send back a string var from ProParty.php and load it into the tag ID "PartyTitle". However I'm getting this error:

Uncaught SyntaxError: Unexpected identifier

On this line: context: document.getElementById("PartyTitle").innerHTML

Here is the ajax that loads with the body of the document:

$.ajax({
      url: "ProParty.php",
      data: { Action: "Load", loadWhat : "PartyName" , PartyId: "1" },
      type: "GET",
      context: document.getElementById("PartyTitle").innerHTML
    }).done(function() {

    });

Here is the HTML tag that I want to edit/fill.

<h2><p id= "PartyTitle"> Editing Your Party  </h2>
WhiteShadow
  • 303
  • 4
  • 18

2 Answers2

2

You are missing a comma after "GET" on the previous line. The following should work:

$.ajax({
  url     : "ProParty.php",
  data    : { Action: "Load", loadWhat : "PartyName" , PartyId: "1" },
  type    : "GET",
  context : document.getElementById("PartyTitle").innerHTML
}).done(function() {

});

*Edit to answer your question in the above comments

$.ajax({
  url     : "ProParty.php",
  data    : { Action: "Load", loadWhat : "PartyName" , PartyId: "1" },
  type    : "GET",
  success : function (data) {
    $('#PartyTitle').html(data);
  }
});

-- with load ( http://api.jquery.com/load/ ) --

$('#PartyTitle').load('ProParty.php', { Action: "Load", loadWhat: "PartyName", PartyId: "1" });
Kenny Thompson
  • 1,494
  • 12
  • 28
  • +1 I understand question like that too, even you could use `load()` instead, which exists for this exact purpose. That's said, passing data as object to load() make it request of type POST – A. Wolff Jun 19 '14 at 17:36
  • 1
    You would be using less code. It sounds like it calls ajax in the background anyways. See: http://forum.jquery.com/topic/jquery-load-vs-jquery-ajax and http://stackoverflow.com/questions/1246137/ajax-jquery-load-versus-jquery-get – Kenny Thompson Jun 19 '14 at 17:38
  • 1
    Ya, `load()` is a shorthand for some ajax request, setting content on matched element – A. Wolff Jun 19 '14 at 17:39
  • @KennyThompson I just started playing with ajax yesterday so I'm really limping along. I know its a lot but could you rewrite this to use load() so that I can see how it transfers over? – WhiteShadow Jun 19 '14 at 17:43
  • Thank you Very much! Is there some way that I can give you some extra points or something? – WhiteShadow Jun 19 '14 at 17:48
  • @A.Wolff lol... sorry.. I thought you were the OP this whole time.. my bad. – Kenny Thompson Jun 19 '14 at 17:49
  • @WhiteShadow I don't think so. =] Thanks for the upvote/answer selection. that's enough – Kenny Thompson Jun 19 '14 at 17:50
  • @KennyThompson None of my variables seem to be passing through. Is this the propper with to access them in php? `$loadWhat = $_GET['loadwhat'];` – WhiteShadow Jun 19 '14 at 18:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55931/discussion-between-kenny-thompson-and-whiteshadow). – Kenny Thompson Jun 19 '14 at 18:00
1

According to the API documentation, context should be a plain object not a string.

Change your code like so:

$.ajax({
  url: "ProParty.php",
  data: { Action: "Load", loadWhat : "PartyName" , PartyId: "1" },
  type: "GET",
  context: document.getElementById("PartyTitle")
}).done(function() {
    // Reference the element as $(this)...
});

Reference: jQuery.ajax()

War10ck
  • 12,387
  • 7
  • 41
  • 54