Jump to content

Recommended Posts

This code doesn't work/execute anything ( ajax_request.php works fine)

 

    $.post("ajax_request.php", { vote: "a", id: "2", category: "0" },
      function(data) {
      $("div#result_a_show").text("" + data.a);
      $("div#result_b_show").text("" + data.b);
      $('a#next_link').attr('href', data.link);
      }, "json");   

Link to comment
https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/
Share on other sites

I think you're using the function incorrect.

Try something like:

$.post({
  url: 'yoururlhere.php',
  data: {data: 'here'}
  dataType: 'json',
  success: function(data) {
    // do stuff here when the data returns
  }
});

 

i tried this. but now all the code doesn't working.

 

    $.post({
      url: 'ajax_request.php',
      data: { vote: 'b', id: '2', category: '0' }
      dataType: 'json',
      success: function(data) {
        $("div#result_a_show").text("" + data.a);
        $("div#result_b_show").text("" + data.b);
        $('a#next_link').attr('href', data.link);
      }
      });

you forgot a comma after the data line

 data: { vote: 'b', id: '2', category: '0' },// comma here

 

Have you got something like firebug it's a lot easier to see what you have done wrong if you get some sort off error feedback

It does do something it doesn't find the url. It's because jQuery.post() and jQuery.ajax() work differently.

Use firebug to see what's going on.

If you change $.post to $.ajax and add type:'post as parameter it should prob work.

 

$.ajax({
    type:'post'
});

I downloaded FireBug. Is says that the POST send successful and it gets the right response but the problem has I already said before is that it doesn't execute the success function. I tried to add alert into it but i doesn't apper as well. ( My feeling that jQuery hates me  :'( )

What I suggested works fine for me. what does your code look like now?

Edit I took a look at the link and noticed the change try a console.log and see if something happens. or do a

alert('some text') 

that way you'll be sure the function runs

I have finally found out that the problem is the PHP file  ::)

its output starts in the third line..

 

could you maybe show what you mean by that, and what was the solution. sorry for asking but i am pretty eager to learn this :D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.