Thursday, 30 August 2018

To send php variables to the php file using jquery ajax?


I want to send a php variable $thread_id to php file using jquery ajax, so the php file can get all posts for $thread_id and echo it back to main file.


it doesnt work when i type:
$.get("ajaxcall_reply.php", thread_id: $thread_id, function(data) {
     $("#threads").html(data);
});

how should i type?

Do you know what $thread_id is outputting? Try putting it into a variable of its own and looking at the output before putting it in the get function. It might have symbols or things that are messing up your javascript syntax. Do you have an example output? Additionally the get method returns the XMLHttpRequest object (data) so you might want to look into setting the type of data to be returned to callback function: "xml", "html", "script", "json", "jsonp", or "text".

0 comments:

Post a Comment