mercredi 2 mars 2016

How to pass an array of variables from a laravel controller to my ajax function

I have an ajax function:

  $.get('/updateAssignment', {title: title, id: id, class: subject, date: date, description: description}, function(data)
  {

    window.location.hash = data;

  });

And it works fine, this is my function in my controller that is routed to the above ajax call:

public function updateAssignment()
{

  // Bunch of code here

  return 'hello world';

}

Now I know that whatever I return, will be in the jQuery variable data, but I want more than one "value".

How would I return something like

return array('title' => $title, 'description' => $description, etc...) 

to my data variable in jQuery and be able to use it like:

$('h2').val(data['title']); Or anything similar

Thank you in advance, I appreciate any help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire